help with this struct

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • learnfpga@gmail.com

    help with this struct

    I cant understand what does the 4th line do in this snippet

    //struct byLightning * pPrevNode;

    typedef struct byLightning
    {
    int data;
    int nodeNum;
    struct byLightning * pPrevNode;
    } LIST_NODE;

    Thanks for any responses....

  • Richard Bos

    #2
    Re: help with this struct

    learnfpga@gmail .com wrote:
    I cant understand what does the 4th line do in this snippet
    >
    //struct byLightning * pPrevNode;
    >
    typedef struct byLightning
    {
    int data;
    int nodeNum;
    struct byLightning * pPrevNode;
    } LIST_NODE;
    It contains the opening brace which begins the structure definition. You
    probably didn't have a problem with that 4th line, so please specify
    which 4th line you really meant.

    Richard

    Comment

    • Mark McIntyre

      #3
      Re: help with this struct

      On 18 Jul 2006 08:01:57 -0700, in comp.lang.c , learnfpga@gmail .com
      wrote:
      >I cant understand what does the 4th line do in this snippet
      Which 4th line? The opening curly brace, the int nodeNum or the
      structbyLightni ng one? [all of these are the 4th line, counting from
      somewhere in your post...]
      >//struct byLightning * pPrevNode;
      >
      >typedef struct byLightning
      {
      int data;
      int nodeNum;
      struct byLightning * pPrevNode;
      this declares a pointer to the previous node in the linked list. If
      you're not sure what a linked list is, you probably need to get a good
      C textbook.
      } LIST_NODE;
      >
      >Thanks for any responses....
      --
      Mark McIntyre

      "Debugging is twice as hard as writing the code in the first place.
      Therefore, if you write the code as cleverly as possible, you are,
      by definition, not smart enough to debug it."
      --Brian Kernighan

      Comment

      • Fred Kleinschmidt

        #4
        Re: help with this struct


        <learnfpga@gmai l.comwrote in message
        news:1153234916 .991282.251970@ h48g2000cwc.goo glegroups.com.. .
        >I cant understand what does the 4th line do in this snippet
        >
        //struct byLightning * pPrevNode;
        >
        typedef struct byLightning
        {
        int data;
        int nodeNum;
        struct byLightning * pPrevNode;
        } LIST_NODE;
        >
        Thanks for any responses....
        >
        Well, let's see. First, I'll assign line numbers, so I can figure out
        what you are talking about:

        1 //struct byLightning * pPrevNode;
        2
        3 typedef struct byLightning
        4 {
        5 int data;
        6 int nodeNum;
        7 struct byLightning * pPrevNode;
        8 } LIST_NODE;

        The 4th line is an opening curly brace for the stuct definition.

        --
        Fred L. Kleinschmidt
        Boeing Associate Technical Fellow
        Technical Architect, Software Reuse Project





        Comment

        • Norbert Kolvenbach

          #5
          Re: help with this struct

          learnfpga@gmail .com schrieb:
          >
          I cant understand what does the 4th line do in this snippet
          >
          //struct byLightning * pPrevNode;
          >
          typedef struct byLightning
          {
          int data;
          int nodeNum;
          struct byLightning * pPrevNode;
          } LIST_NODE;
          >
          Thanks for any responses....
          Try to understand linked lists.

          --
          "Careful with that VAX, Eugene!"

          Comment

          • lovecreatesbeauty

            #6
            Re: help with this struct


            learnfpga@gmail .com wrote:
            I cant understand what does the 4th line do in this snippet
            >
            //struct byLightning * pPrevNode;
            >
            typedef struct byLightning
            {
            int data;
            int nodeNum;
            struct byLightning *pPrevNode;
            } LIST_NODE;
            This is a self-referral structure. The third member is a pointer to an
            object of same type as the structure itself. The declaration of the
            third member is ok because the base type of the pointer is known, at
            that time the info of the type is enough to declare a pointer. All
            pointers are the same and have the same size.

            Comment

            • Chris Dollin

              #7
              Re: help with this struct

              lovecreatesbeau ty wrote:
              >
              learnfpga@gmail .com wrote:
              >I cant understand what does the 4th line do in this snippet
              >>
              >//struct byLightning * pPrevNode;
              >>
              >typedef struct byLightning
              >{
              > int data;
              > int nodeNum;
              > struct byLightning *pPrevNode;
              >} LIST_NODE;
              >
              This is a self-referral structure. The third member is a pointer to an
              object of same type as the structure itself. The declaration of the
              third member is ok because the base type of the pointer is known, at
              that time the info of the type is enough to declare a pointer. All
              pointers are the same and have the same size.
              Not necessarily true.

              My recollection is that all /struct/ pointers must [1] be the same size
              (as a consequence of things the Standard says). But there's no
              requirement that an int* and a char* are the same size, or that
              a function pointer be the same size as a void* -- it could be smaller
              /or bigger/.

              [1] Up to "as if".

              --
              Chris "seeker" Dollin
              "Life is full of mysteries. Consider this one of them." Sinclair, /Babylon 5/

              Comment

              Working...