By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,873 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

Structure type definition in different files?

P: n/a
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.

Apr 10 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
WaterWalk wrote:
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.

--
Eric Sosman
es*****@acm-dot-org.invalid
Apr 10 '06 #2

P: n/a
WaterWalk wrote:

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.

--
pete
Apr 10 '06 #3

P: n/a

Eric Sosman 写道:
WaterWalk wrote:
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.


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

Apr 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.