473,324 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Structure type definition in different files?

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
3 2787
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
2
by: Madhav | last post by:
Hi all, I was going through a piece of code which had a very interesting format. There were two files: one was a .h file, and the other was a .c file. The .c file had a structure defined in it...
3
by: Sin | last post by:
Hello everybody, I'm currently trying to understand how marshaling can use used for accessing Win32 API functions as well as custom C/C++ code we design which exposes functions the same way as...
20
by: dspfun | last post by:
I've come a across a program that declares the following data structure. typedef struct node { struct node *next; } node; It looks like a recursive data structure but I'm having trouble...
2
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
3
by: DhaneshNair | last post by:
Hi all, I hav a file which is actually linkage file (used as an reference interface between c and c++ files). And this file has got two structures in it .. When i include this file directly i...
2
by: Pedro Pinto | last post by:
Hi there! I'm presented with the following situation: I'm writing a server program that receives information and saves it to a structure i've created that goes by the name of tabela. The...
6
by: Scoots | last post by:
I know the usually applied workaround for multiple definitions of header files, but I have a problem on this one. This time, I can't just ifndef the header file that defines my structure. So...
17
by: Jason Doucette | last post by:
I am converting a C-style unit into a C++ class. I have an implementation function that was defined in the .cpp file (so it was hidden from the interface that exists in the .h file). It uses a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.