structure typedefs

Roger Gonzalez rg at uunet!unhd
Thu Mar 29 01:07:55 AEST 1990


Could someone kindly explain to me the difference between

typedef struct  foo {				typedef struct  {
    ..						    ..
};				and		}   foo;

struct foo  bar;				foo bar;


In some situations, it doesn't make any difference at all.  In others, most
notably when you have a pointer to the same type (i.e. linked list stuff)

typedef struct	foo {
    ..
    struct foo *next;
};

struct foo  bar;

I seem to recall even seeing this:

typedef struct  foo {
    ..
    struct foo *next;
} foo;

foo bar;

Which looks to me like it should cause an error.  Please enlighten me as to
the subtleties of this.  I'm not a novice C programmer, and I've been using
structures for years, and I know how to make them work, but I've never really
understood exactly what was going on internally.  Email if possible; I don't
read this group often.

-Roger

-- 
UUCP:   ..!uunet!unhd!rg      | USPS: Marine Systems Engineering Laboratory
BITNET: r_gonzalez at unhh    |       University of New Hampshire
PHONE:  (603) 862-4600        |       Marine Programs Building
FAX:    (603) 862-4399        |       Durham, NH  03824-3525



More information about the Comp.lang.c mailing list