Õ
ÕÅÔ´ Î÷±±¹¤Òµ´óѧ
On 5/31/2012 3:10 PM, Kulin wrote:
[...]
My desire is simply to avoid having to create pointers as struct * inside
the structure. Other than that I would tend to agree.
typedef struct A B; // "incomplete type" declaration
can i understand in this way:the ambiguity of struct A is B ?
I don't know what you mean by "the ambiguity of." The line
actually says two things:
1) A type named `struct A' exists. The type is "incomplete,"
meaning that there is no information about the number of bytes a
`struct A' requires or what its member elements are. Perhaps the
code will provide such details later to "complete" the type, but
no details are available yet.
2) `B' is an alias for `struct A'. `B' and `struct A' can
be used interchangeably; both refer to the exact same type. Since
`struct A' is an incomplete type, `B' is also an incomplete type
(because it is, in fact, the same type).
These lines "complete" the `struct A' type by describing the
struct elements. Since `struct A' is now complete, its alias `B'
is also complete: As before, `struct A' and `B' mean the same thing.
--
Eric Sosman
(e-mail address removed)
On 5/31/2012 3:10 PM, Kulin wrote:
[...]
My desire is simply to avoid having to create pointers as struct * inside
the structure. Other than that I would tend to agree.
typedef struct A B; // "incomplete type" declaration
can i understand in this way:the ambiguity of struct A is B ?
I don't know what you mean by "the ambiguity of." The line
actually says two things:
1) A type named `struct A' exists. The type is "incomplete,"
meaning that there is no information about the number of bytes a
`struct A' requires or what its member elements are. Perhaps the
code will provide such details later to "complete" the type, but
no details are available yet.
2) `B' is an alias for `struct A'. `B' and `struct A' can
be used interchangeably; both refer to the exact same type. Since
`struct A' is an incomplete type, `B' is also an incomplete type
(because it is, in fact, the same type).
These lines "complete" the `struct A' type by describing the
struct elements. Since `struct A' is now complete, its alias `B'
is also complete: As before, `struct A' and `B' mean the same thing.
thanks a lot,sorry for my awful english,since i'm a Chinese.
can you exlain why the code below are forbidden ?
typedef struct A {
A *p1; /* not allowed */
B *p2; /* not allowed */
} B;
This gives compilation errors.