Structures and Linked Lists (hopefully a really stupid question)

Discussion in 'C Programming' started by Daniel Rudy, Jan 23, 2007.

  1. Daniel Rudy

    Daniel Rudy Guest

    Consider the following two code fragments:

    Example 1:

    typedef struct datatype_tag
    {
    char section[64];
    char name[64];
    char value[1024];
    datatype_t *next;
    } datatype_t;



    Example 2:

    typedef struct datatype_tag
    {
    char section[64];
    char name[64];
    char value[1024];
    struct datatype_tag *next;
    } datatype_t;



    Now the first one generates a syntax error from gcc. The second one
    works just fine. Why?

    I'm thinking it has to do with me using the typedef'd identifier in the
    middle of the typedef declaration? If that's the case, will it be ok
    with the second form?



    --
    Daniel Rudy

    Email address has been base64 encoded to reduce spam
    Decode email address using b64decode or uudecode -m

    Why geeks like computers: look chat date touch grep make unzip
    strip view finger mount fcsk more fcsk yes spray umount sleep
     
    Daniel Rudy, Jan 23, 2007
    #1
    1. Advertising

  2. Daniel Rudy wrote:
    > Consider the following two code fragments:
    >
    > Example 1:
    >
    > typedef struct datatype_tag
    > {
    > char section[64];
    > char name[64];
    > char value[1024];
    > datatype_t *next;
    > } datatype_t;
    >
    >
    >
    > Example 2:
    >
    > typedef struct datatype_tag
    > {
    > char section[64];
    > char name[64];
    > char value[1024];
    > struct datatype_tag *next;
    > } datatype_t;
    >
    >
    >
    > Now the first one generates a syntax error from gcc. The second one
    > works just fine. Why?
    >
    > I'm thinking it has to do with me using the typedef'd identifier in the
    > middle of the typedef declaration? If that's the case, will it be ok
    > with the second form?
    >


    This is question 1.14 of the FAQ which can be
    found at http://c-faq.com/
     
    Spiros Bousbouras, Jan 23, 2007
    #2
    1. Advertising

  3. Daniel Rudy

    Daniel Rudy Guest

    At about the time of 1/22/2007 6:42 PM, Spiros Bousbouras stated the
    following:
    > Daniel Rudy wrote:
    >> Consider the following two code fragments:
    >>
    >> Example 1:
    >>
    >> typedef struct datatype_tag
    >> {
    >> char section[64];
    >> char name[64];
    >> char value[1024];
    >> datatype_t *next;
    >> } datatype_t;
    >>
    >>
    >>
    >> Example 2:
    >>
    >> typedef struct datatype_tag
    >> {
    >> char section[64];
    >> char name[64];
    >> char value[1024];
    >> struct datatype_tag *next;
    >> } datatype_t;
    >>
    >>
    >>
    >> Now the first one generates a syntax error from gcc. The second one
    >> works just fine. Why?
    >>
    >> I'm thinking it has to do with me using the typedef'd identifier in the
    >> middle of the typedef declaration? If that's the case, will it be ok
    >> with the second form?
    >>

    >
    > This is question 1.14 of the FAQ which can be
    > found at http://c-faq.com/
    >


    I was looking for that. Thank you for the link.


    --
    Daniel Rudy

    Email address has been base64 encoded to reduce spam
    Decode email address using b64decode or uudecode -m

    Why geeks like computers: look chat date touch grep make unzip
    strip view finger mount fcsk more fcsk yes spray umount sleep
     
    Daniel Rudy, Jan 23, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Ritchey
    Replies:
    7
    Views:
    511
    emerth
    Jul 10, 2003
  2. Chris Ritchey

    Generating a char* from a linked list of linked lists

    Chris Ritchey, Jul 9, 2003, in forum: C Programming
    Replies:
    7
    Views:
    501
    emerth
    Jul 10, 2003
  3. Replies:
    25
    Views:
    830
  4. Alfonso Morra
    Replies:
    11
    Views:
    753
    Emmanuel Delahaye
    Sep 24, 2005
  5. jawdoc
    Replies:
    9
    Views:
    804
    Chris Thomasson
    Mar 10, 2008
Loading...

Share This Page