The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: rags on November 11, 2008, 03:06:04 AM

Title: C struct question
Post by: rags on November 11, 2008, 03:06:04 AM
I am not familiar with c, and was looking at some c code and came across this struct def:


typedef struct _Info
{
.....
       .....
       some declarations
      ......
} Info;


Is this a structure named Info of type _Info or is it the otherway around?
thanks
Title: Re: C struct question
Post by: hutch-- on November 11, 2008, 03:11:30 AM
Mike,

The trailing name is the one to use. A C compiler reads the structure in a linear manner from "{" to "}" then reads the name after it.
Title: Re: C struct question
Post by: rags on November 11, 2008, 03:19:25 AM
thanks for the quick reply Hutch
Title: Re: C struct question
Post by: BogdanOntanu on November 11, 2008, 05:13:13 AM
Not exactly

This is the lazy version of 2 statements: one for the typedef and another one for the structure.

Hence in this "single" compound statement the structure _Info is defined in the inner part of the statement and then a new type is created in the outer part of the statement. A type named "Info" that is typedf'ed as being the same as "struct _Info".

The struct _Info also does exist for the compiler.

This typedef is usually made because people do not like to type "struct _Info" all over the place.

But Hutch is right in the short answer: the last name is the one that is usually used.