Like Tree1Likes
  • 1 Post By laserlight

dumb struct question

This is a discussion on dumb struct question within the C Programming forums, part of the General Programming Boards category; Suppose I define a structure like this Code: typedef struct foo { /* some data */ } foo_t; To be ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    2

    dumb struct question

    Suppose I define a structure like this

    Code:
    typedef struct foo {
         /* some data */
    } foo_t;
    To be used 'XXX' times in another structure. What is different between:

    Code:
    typedef struct yyy {
        foo_t    name[XXX];
    } yyy_t;
    and..

    Code:
    typedef struct yyy {
        struct foo    name[XXX];
    } yyy_t;
    ?? If they are the same, which is preferred and why?

    Thanks!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    They are effectively the same, and since the typedef name is provided, you might as well use it. The difference comes when you want to refer to struct foo from within struct foo's definition: since the typedef exists outside of the definition of struct foo, you must then use struct foo, not foo_t (unless you write a separate typedef before the definition of struct foo).
    Salem likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    2
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. maybe a dumb question
    By Yarin in forum C++ Programming
    Replies: 10
    Last Post: 01-28-2008, 04:23 PM
  2. Dumb Question
    By Death_Wraith in forum C++ Programming
    Replies: 5
    Last Post: 07-02-2004, 09:54 AM
  3. Dumb MFC question.
    By Sebastiani in forum Windows Programming
    Replies: 3
    Last Post: 12-11-2002, 10:24 AM
  4. dumb question
    By dP munky in forum Tech Board
    Replies: 14
    Last Post: 12-09-2002, 02:06 PM
  5. Sorry for a dumb question.
    By Vanished in forum C++ Programming
    Replies: 7
    Last Post: 11-23-2002, 12:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21