help needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • A.C.

    help needed

    hi
    i m declaring a structure globally & there is func1 & main.
    i m assigning the value to variable(this is a pointer) of structure in
    fun1 & want to print it in main.
    this is same kind of problem not the actual code. pls help.


    static struct des_rbuf{
    unsigned int ind;
    long long buf_adr;
    unsigned int len;
    }desc_rbuf[512];

    static l;
    int main()
    {
    fun1();
    for(p=0;p<l;p++ )
    PRINT("%u\t\t\t \t%x\t\t\t
    %u",desc_rbuf[p].ind,desc_rbuf[p].buf_adr,desc_r buf[p].len);
    //here it is printing all the values 0
    }

    fun1
    {
    desc_rbuf[l].ind=i;
    desc_rbuf[l].buf_adr=(rxd->buffer_addr&0x FFFFFFFF);
    desc_rbuf[l].len=rxd->length;
    l++;

    //here the value desc_rbuf[l] is printing right
    }
  • vippstar@gmail.com

    #2
    Re: help needed

    On Sep 24, 3:03 pm, "A.C." <ankitc.bitspil ...@gmail.comwr ote:
    hi
    i m declaring a structure globally & there is func1 & main.
    i m assigning the value to variable(this is a pointer) of structure in
    fun1 & want to print it in main.
    this is same kind of problem not the actual code. pls help.
    Please post compilable code.

    PRINT() is nowhere defined.
    fun1 { is a syntax error.
    p is nowhere declared.

    Regardless, static l; means l equals 0.
    for(p = 0; p < l; p++)
    That loop is skipped, because 0 < 0 is false.

    [ blame google if this appears twice ]

    Comment

    • A.C.

      #3
      Re: help needed

      On Sep 24, 5:26 pm, vipps...@gmail. com wrote:
      On Sep 24, 3:03 pm, "A.C." <ankitc.bitspil ...@gmail.comwr ote:
      >
      >Please post compilable code.
      >
      PRINT() is nowhere defined.
      fun1 { is a syntax error.
      p is nowhere declared.
      >
      Regardless, static l; means l equals 0.
      for(p = 0; p < l; p++)
      That loop is skipped, because 0 < 0 is false.
      >
      [ blame google if this appears twice ]
      well this was a same looking code. PRINT is same as printf(); that we
      have defined in macro.
      problem is not in compilation...
      problem is that the PRINT in main(), giving all the values 0 for every
      varible fo desc_tbuf[p].everything


      #include <stdio.h>
      #include <stdlib.h>
      #include "debug.h"

      int n,m;
      static int l=0,z=0,y=0;

      static struct tool_buf{
      unsigned char *reg_name;
      unsigned int reg_val;
      unsigned char *reg_info;

      }in_buf[100];

      /*for Rx descriptor info*/
      static struct des_rbuf{
      unsigned int ind;
      long long buf_adr;
      unsigned int len;
      }desc_rbuf[512];

      /*for Tx descriptor info*/
      static struct des_tbuf{
      unsigned int ind;
      long long buf_adr;
      unsigned int len;
      }desc_tbuf[512];


      int main()
      {
      uint8_t r_type;
      const char *filename="data .txt";
      uint32_t val,reg;
      char buf[200],reg_type[20];
      int i,j,k,o,p;
      FILE *fp=fopen(filen ame,"r");
      int a,b,f,g;
      char c,d,e,real_len[10];



      if(fp)
      {
      for(i=0;i<5;i++ )
      fgets(buf,sizeo f(buf),fp);

      while(fgets(buf ,sizeof(buf),fp ))
      {
      if(buf[17]=='R'&&buf[18]=='x')
      {
      r_type=RX;
      PRINT("\n\n%s", buf);

      for(j=0;j<4;j++ )
      {
      fgets(buf,sizeo f(buf),fp);
      PRINT("%s",buf) ;
      }

      while(fgets(buf ,sizeof(buf),fp ))
      {
      if((buf[0]=='c'&&buf[1]=='u')||buf[0]=='\n')
      continue;

      sscanf(buf,"%3d :",&i);
      if(i>=0&&i<512)
      {
      ns_nic_desc_inf o(r_type,buf);
      if(i==511) break;
      }
      }
      }

      }

      }
      PRINT("\n\n\n
      =============== =============== =============== =============== =============== =============== =============== =============== ==");
      /*Register information*/
      PRINT("\nHere are The Probable Causes of Errors\n");
      PRINT("\nRegist ers Information");
      PRINT("\n%32s\t \tValue(Hexa)\t \tDescription
      \n","Field.Regi ster_Name)");

      for(n=0;n<y;n++ )
      {
      PRINT("\n%35s\t \t0x%x\t\t\t%s" ,in_buf[n].reg_name,
      in_buf[n].reg_val, in_buf[n].reg_info );
      }
      PRINT("\n\n
      \n============= =============== =============== =============== =============== =============== =============== =============== ============");
      /*for Rx ring information*/
      PRINT("\nDescri ptors Information About Errors RxRing\n");
      PRINT("\n\n\tin dex Value\t\t\tBuff er Address\t\tLeng th");

      for(p=0;p<l;p++ )
      {
      sprintf(real_le n,"%d",desc_rbu f[p].len);
      PRINT("\n\t%u\t \t\t\t%x\t\t\t
      %s",desc_rbuf[p].ind,desc_rbuf[p].buf_adr,real_l en);
      }

      /*for Tx ring information*/
      PRINT("\n\nDesc riptors Information About Errors TxRing\n");
      PRINT("\n\tinde x Value\t\t\tBuff er Address\t\tLeng th");

      for(p=0;p<z;p++ )
      {
      //this is giving all values as 0
      PRINT("\n\t%u\t \t\t\t%x\t\t\t
      %u",desc_tbuf[p].ind,desc_tbuf[p].buf_adr,desc_t buf[p].len);
      }


      return;
      }


      void ns_nic_desc_inf o(uint8_t ring_type,char *buf)
      {
      int i,j,ac;
      char *str1="99999999 ";
      ac= atoi(str1);

      em_rx_desc_t rxd_inst;
      em_rx_desc_t *rxd=&rxd_inst;
      em_tx_desc_t txd_inst;
      em_tx_desc_t *txd=&txd_inst;


      switch(ring_typ e) {
      case RX:
      sscanf(buf,"%3d : @%8x %4d %2x %2x %4x",&i,&rxd->buffer_addr,&r xd-
      >length,&rxd->status,&rxd->errors,&rxd->special);
      /* dump the data */

      PRINT("\n%3d:: %15s %8x",i,"Buffer Address:",(rxd-
      >buffer_addr&0x FFFFFFFF));
      PRINT("\n %15s\t%d","Leng th:",rxd->length);
      /*status description*/
      PRINT("\n %15s\t0x%x","St atus:",rxd->status);
      PRINT("\n %20s\t0x%x\t%s" ,"DD(0)",(rx d->status&0x1),"D ESCRIPTOR
      DONE");
      PRINT("\n %20s\t0x%x\t%s" ,"EOP(1)",(r xd->status&0x2),"E ND OF
      PACKET");
      PRINT("\n %20s\t0x%x\t%s" ,"IXSM(2)",( rxd->status&0x4),"I GNORE
      CHECKSUM INDICATION");
      PRINT("\n %20s\t0x%x\t%s" ,"VP(3)",(rx d->status&0x8),"P ACKET IS
      802.1Q");
      PRINT("\n %20s\t0x%x\t%s" ,"TCPCS(5)",(rx d->status&0x20)," TCP
      CHECKSUM CALCULATED ON PACKET");
      PRINT("\n %20s\t0x%x\t%s" ,"IPCS(6)",( rxd->status&0x40)," IP
      CHECKSUM CALCULATED ON PACLKET");
      PRINT("\n %20s\t0x%x\t%s" ,"PIF(7)",(r xd->status&0x80)," PASSED IN-
      EXACT FILTER");
      /*Errors description*/
      PRINT("\n %15s\t0%x","Err ors:",rxd->errors);
      PRINT("\n %20s\t0x%x\t%s" ,"CE(0)",(rx d->errors&0x1),"C RC ERROR OR
      ALIGNMENT ERROR");
      PRINT("\n %20s\t0x%x\t%s" ,"SE(1)",(rx d->errors&0x2),"S YMBOL
      ERROR");
      PRINT("\n %20s\t0x%x\t%s" ,"SEQ(2)",(r xd->errors&0x4),"S EQUENCE
      ERROR");
      PRINT("\n %20s\t0x%x\t%s" ,"CXE RXV(4)",(rxd->errors&0x10)," CARRIER
      EXTENSION ERROR");
      PRINT("\n %20s\t0x%x\t%s" ,"TCPE(5)",( rxd->errors&20),"TC P/UDP
      CHECKSUM ERROR");
      PRINT("\n %20s\t0x%x\t%s" ,"IPE(6)",(r xd->errors&40)," IP CHECKSUM
      ERROR");
      PRINT("\n %20s\t0x%x\t%s" ,"RXE(7)",(r xd->errors&80)," RX DATA
      ERROR");
      /*Special filed description*/
      PRINT("\n %15s\t0x%x","Sp ecial:",rxd->special);
      PRINT("\n %20s\t0x%x\t%s" ,"VLAN(11:0)",( rxd->special&0xFFF) ,"VALN
      IDENTIFIER");
      PRINT("\n %20s\t0x%x\t%s" ,"CFI(12)",( rxd-
      >special&0x1000 ),"CANONICAL FORM INDICATOR");
      PRINT("\n %20s\t0x%x\t%s" ,"PRI(15:13)",( rxd->special&0xE000 ),"USER
      PRIORITY");


      if(rxd->status&0x1)/*dd is 1*/
      {
      if((rxd->buffer_addr&0x FFFFFFFF)==0x0| |(rxd->length)==0)
      {
      desc_rbuf[l].ind=i;
      desc_rbuf[l].buf_adr=(rxd->buffer_addr&0x FFFFFFFF);
      desc_rbuf[l].len=rxd->length;
      l++;

      }

      }

      if(i==511)
      {
      desc_rbuf[l].ind=ac;
      desc_rbuf[l].buf_adr=0;
      desc_rbuf[l].len=0;
      l++;

      }



      break;

      case TX:


      break;
      }
      }






      there is log file that we take input
      u can assign value to the variables in the function ns_nic_desc_inf o &
      try to print in main.
      any other symbol or function that is not standard 'C' that is d3efined
      in our macros
      so pls ignore it.
      i tried with pointers also but again same problem, whereever u r
      allocating the memoty :-(
      try something or if u know
      pls help me.


      Comment

      • jameskuyper@verizon.net

        #4
        Re: help needed

        A.C. wrote:
        ....
        any other symbol or function that is not standard 'C' that is d3efined
        in our macros
        so pls ignore it.
        I tried that, by inserting the following lines at the beginning of
        your program:

        #ifdef UNKNOWN
        #include "debug.h"
        #else
        #define uint8_t
        #define uint32_t
        #define RX
        #define PRINT(a, ...)
        #define em_rx_desc_t
        #define em_tx_desc_t
        #define ring_type
        #define buf
        #define TX
        void ns_nic_desc_inf o(uint8_t, char *);
        #endif

        It didn't help much.

        If you want other people to help you, we need complete COMPILABLE
        code. For each of those identifiers, give us code that either defines
        the identifier, or doesn't use it. You might think you know where
        your problem is, and that it doesn't depend upon the things you
        haven't given us. However, you came to us for help with a problem that
        you couldn't resolve. That means that you don't know what the problem
        is, which means that you can't be sure where the problem is. The only
        way you can be sure that you've given us enough information, is if you
        give us ALL the information.

        Comment

        • Richard

          #5
          Re: help needed

          jameskuyper@ver izon.net writes:
          A.C. wrote:
          ...
          >any other symbol or function that is not standard 'C' that is d3efined
          >in our macros
          >so pls ignore it.
          >
          I tried that, by inserting the following lines at the beginning of
          your program:
          >
          #ifdef UNKNOWN
          #include "debug.h"
          #else
          #define uint8_t
          #define uint32_t
          #define RX
          #define PRINT(a, ...)
          #define em_rx_desc_t
          #define em_tx_desc_t
          #define ring_type
          #define buf
          #define TX
          void ns_nic_desc_inf o(uint8_t, char *);
          #endif
          >
          It didn't help much.
          >
          If you want other people to help you, we need complete COMPILABLE
          code. For each of those identifiers, give us code that either defines
          Once does not need complete or compilable code in a lot of cases.

          Comment

          • Stephen Sprunk

            #6
            Re: help needed

            Richard wrote:
            jameskuyper@ver izon.net writes:
            >If you want other people to help you, we need complete COMPILABLE
            >code. For each of those identifiers, give us code that either defines
            >
            Once does not need complete or compilable code in a lot of cases.
            True, but the person asking for help is the person least likely to be
            able to distinguish what is necessary and what is not. Asking them to
            send everything removes that possible problem.

            S

            Comment

            • Richard

              #7
              Re: help needed

              Stephen Sprunk <stephen@sprunk .orgwrites:
              Richard wrote:
              >jameskuyper@ver izon.net writes:
              >>If you want other people to help you, we need complete COMPILABLE
              >>code. For each of those identifiers, give us code that either defines
              >>
              >Once does not need complete or compilable code in a lot of cases.
              >
              True, but the person asking for help is the person least likely to be
              able to distinguish what is necessary and what is not. Asking them to
              send everything removes that possible problem.
              >
              S
              Yes. Asking them is one thing. To insist on it for all issues and
              questions is, however, a different thing.

              Clearly if some one says "my program doesn't work" help then compilable
              code is generally necessary.

              This was my only point : it is not necessary to have full and complete
              code to help someone in probably the majority of cases.

              Comment

              • jameskuyper@verizon.net

                #8
                Re: help needed

                Richard wrote:....
                If you want other people to help you, we need complete COMPILABLE
                code. For each of those identifiers, give us code that either defines
                >
                Once does not need complete or compilable code in a lot of cases.
                True. If you believe that this is one of those cases, you could prove
                that by identifying what the problem is just from the information he's
                already given us.

                Comment

                • Barry Schwarz

                  #9
                  Re: help needed

                  On Wed, 24 Sep 2008 05:26:20 -0700 (PDT), vippstar@gmail. com wrote:
                  >On Sep 24, 3:03 pm, "A.C." <ankitc.bitspil ...@gmail.comwr ote:
                  >hi
                  >i m declaring a structure globally & there is func1 & main.
                  >i m assigning the value to variable(this is a pointer) of structure in
                  >fun1 & want to print it in main.
                  >this is same kind of problem not the actual code. pls help.
                  >
                  >Please post compilable code.
                  >
                  >PRINT() is nowhere defined.
                  >fun1 { is a syntax error.
                  >p is nowhere declared.
                  >
                  >Regardless, static l; means l equals 0.
                  >for(p = 0; p < l; p++)
                  >That loop is skipped, because 0 < 0 is false.
                  Look again at fun1.

                  --
                  Remove del for email

                  Comment

                  • Barry Schwarz

                    #10
                    Re: help needed

                    On Wed, 24 Sep 2008 05:03:29 -0700 (PDT), "A.C."
                    <ankitc.bitspil ani@gmail.comwr ote:
                    >hi
                    >i m declaring a structure globally & there is func1 & main.
                    >i m assigning the value to variable(this is a pointer) of structure in
                    >fun1 & want to print it in main.
                    >this is same kind of problem not the actual code. pls help.
                    >
                    >
                    >static struct des_rbuf{
                    > unsigned int ind;
                    > long long buf_adr;
                    > unsigned int len;
                    >}desc_rbuf[512];
                    >
                    >static l;
                    >int main()
                    >{
                    >fun1();
                    >for(p=0;p<l;p+ +)
                    >PRINT("%u\t\t\ t\t%x\t\t\t
                    >%u",desc_rbu f[p].ind,desc_rbuf[p].buf_adr,desc_r buf[p].len);
                    >//here it is printing all the values 0
                    >}
                    >
                    >fun1
                    >{
                    >desc_rbuf[l].ind=i;
                    What is i?
                    >desc_rbuf[l].buf_adr=(rxd->buffer_addr&0x FFFFFFFF);
                    What is rxd?
                    >desc_rbuf[l].len=rxd->length;
                    >l++;
                    >
                    >//here the value desc_rbuf[l] is printing right
                    >}
                    Your problem may well be in the code you chose not to post.

                    --
                    Remove del for email

                    Comment

                    • vippstar@gmail.com

                      #11
                      Re: help needed

                      On Sep 25, 5:17 am, Barry Schwarz <schwa...@dqel. comwrote:
                      On Wed, 24 Sep 2008 05:26:20 -0700 (PDT), vipps...@gmail. com wrote:
                      On Sep 24, 3:03 pm, "A.C." <ankitc.bitspil ...@gmail.comwr ote:
                      hi
                      i m declaring a structure globally & there is func1 & main.
                      i m assigning the value to variable(this is a pointer) of structure in
                      fun1 & want to print it in main.
                      this is same kind of problem not the actual code. pls help.
                      >
                      Please post compilable code.
                      >
                      PRINT() is nowhere defined.
                      fun1 { is a syntax error.
                      p is nowhere declared.
                      >
                      Regardless, static l; means l equals 0.
                      for(p = 0; p < l; p++)
                      That loop is skipped, because 0 < 0 is false.
                      >
                      Look again at fun1.
                      fun1 had a syntax error so I completely ignored it.

                      Comment

                      • Richard

                        #12
                        Re: help needed

                        vippstar@gmail. com writes:
                        On Sep 25, 5:17 am, Barry Schwarz <schwa...@dqel. comwrote:
                        >On Wed, 24 Sep 2008 05:26:20 -0700 (PDT), vipps...@gmail. com wrote:
                        >On Sep 24, 3:03 pm, "A.C." <ankitc.bitspil ...@gmail.comwr ote:
                        >hi
                        >i m declaring a structure globally & there is func1 & main.
                        >i m assigning the value to variable(this is a pointer) of structure in
                        >fun1 & want to print it in main.
                        >this is same kind of problem not the actual code. pls help.
                        >>
                        >Please post compilable code.
                        >>
                        >PRINT() is nowhere defined.
                        >fun1 { is a syntax error.
                        >p is nowhere declared.
                        >>
                        >Regardless, static l; means l equals 0.
                        >for(p = 0; p < l; p++)
                        >That loop is skipped, because 0 < 0 is false.
                        >>
                        >Look again at fun1.
                        >
                        fun1 had a syntax error so I completely ignored it.
                        Well, why not point out the other errors too? Does it hurt to do so?

                        Comment

                        Working...