J
James Kuyper
On 02/03/2014 11:59 AM, Robbie Brown wrote:
....
You need to distinguish between defining a struct type, and defining an
object of struct type:
// Defining struct types
struct tag1 { ... };
typedef struct { ... } name1;
typedef struct tag2 { ... } name2;
tag1 and tag2 are struct tags. "struct tag1", name1, "struct tag2", and
name2 are type names; the last two are different type names for the same
exact type. Note: they don't have to be different, and it is in fact
common practice to have the typedef name match the corresponding struct
tag - doing so reduces some of the differences between C and C++.
// Defining objects of struct type
struct tag1 obj2;
name1 obj3;
struct tag2 obj4;
name2 obj5;
// Defining a struct type and an object of that type in the same
// definition:
struct tag3 { ... } obj6;
struct { ... } obj7.
Does that clear it up?
....
So now I appear to have 4 different ways to declare/define a struct.
You need to distinguish between defining a struct type, and defining an
object of struct type:
// Defining struct types
struct tag1 { ... };
typedef struct { ... } name1;
typedef struct tag2 { ... } name2;
tag1 and tag2 are struct tags. "struct tag1", name1, "struct tag2", and
name2 are type names; the last two are different type names for the same
exact type. Note: they don't have to be different, and it is in fact
common practice to have the typedef name match the corresponding struct
tag - doing so reduces some of the differences between C and C++.
// Defining objects of struct type
struct tag1 obj2;
name1 obj3;
struct tag2 obj4;
name2 obj5;
// Defining a struct type and an object of that type in the same
// definition:
struct tag3 { ... } obj6;
struct { ... } obj7.
Does that clear it up?