Thread: dumb struct question

  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
    28,413
    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).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 08: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