Structure type definition in different files?

W

WaterWalk

I read from c99 std TC2 community draft, and found the following
statement in 6.7.2.3:

"Tw o declarations of structure, union, or enumerated types which are
in different scopes or
use different tags declare distinct types. Each declaration of a
structure, union, or
enumerated type which does not include a tag declares a distinct type."

Then consider this common practice. Struct A type is defined in a
header. This header is included by two .c files. After preprocessing,
the struct A type definition is included in those two files. According
to the description of the standard, in those two files, struct A types
definitions will be considered to be two distinct types. I don't know
if I'm right here. But this relly sounds weird.
 
E

Eric Sosman

WaterWalk said:
I read from c99 std TC2 community draft, and found the following
statement in 6.7.2.3:

"Tw o declarations of structure, union, or enumerated types which are
in different scopes or
use different tags declare distinct types. Each declaration of a
structure, union, or
enumerated type which does not include a tag declares a distinct type."

Then consider this common practice. Struct A type is defined in a
header. This header is included by two .c files. After preprocessing,
the struct A type definition is included in those two files. According
to the description of the standard, in those two files, struct A types
definitions will be considered to be two distinct types. I don't know
if I'm right here. But this relly sounds weird.

Yes, they are distinct types. But they are
"compatible types;" see 6.2.7 paragraph 1.
 
P

pete

WaterWalk said:
I read from c99 std TC2 community draft, and found the following
statement in 6.7.2.3:

"Tw o declarations of structure, union, or enumerated types which are
in different scopes or
use different tags declare distinct types. Each declaration of a
structure, union, or
enumerated type which does not
include a tag declares a distinct type."

Then consider this common practice. Struct A type is defined in a
header. This header is included by two .c files. After preprocessing,
the struct A type definition is included in those two files. According
to the description of the standard, in those two files, struct A types
definitions will be considered to be two distinct types. I don't know
if I'm right here. But this relly sounds weird.

I have code like that.
It does really seem weird.
 
W

WaterWalk

Eric Sosman 写é“:
Yes, they are distinct types. But they are
"compatible types;" see 6.2.7 paragraph 1.

Thanks for your help. This rule is similar to C++'s "One Definition
Rule". But IMO the C++'s ODR seems more clear. Interesting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top