Thread: Different Struct Definitions

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    648

    Different Struct Definitions

    I've seen these two different styles in many places. So I'm wondering, whats the difference between these two?
    Code:
    typedef struct
    {
       char *name;
       int id;
    } Tag;
    Code:
    struct Tag
    {
       char *name;
       int id;
    };

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    In the first case, you make a typed definition of the structure meaning you can use it as any datatype (when declaring, in arguments etc...).
    In the second case, you need to specify the keyword 'struct' when declaring variables, which you don't do in the first case.

    Other than that, I believe they are pretty much the same.
    I usually typedef all my structs.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Oh I see, thanks. Well it doesn't matter to me since I'm a C++ programmer!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segfault with Linked List Program
    By kbrandt in forum C Programming
    Replies: 1
    Last Post: 06-23-2009, 07:13 AM
  2. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  3. What's wrong with my search program?
    By sherwi in forum C Programming
    Replies: 5
    Last Post: 04-28-2006, 09:57 AM
  4. Function validation.
    By Fhl in forum C Programming
    Replies: 10
    Last Post: 02-22-2006, 08:18 AM
  5. Search Engine - Binary Search Tree
    By Gecko2099 in forum C Programming
    Replies: 9
    Last Post: 04-17-2005, 02:56 PM