473,623 Members | 2,433 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2804
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
4240
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 char* formatter, ...); Then, I want to call it as so:
2
2469
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 which was typedef'ed in .h file. what I observered was even more interesting: I was allowed to declare objects of structure that was typedefed in the header file, but I could not use any of the members of the structure outside the .c file which...
3
2331
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 the Win32 API. I figured how to use strings... No problem there, there was a couple undred examples on the net. I have yet to find how to do the same with an array of integers for example... Here's my test code :
20
8796
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 understanding the use of it? Can somebody explain this?
2
3268
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 and arrays of pointers to them. I have gotten the program to compile with gcc on WinXP. If the file i read doesnt have alot of records, it runs thru. But once i add more, it dies. In this program i have 4 files setup to read. The
3
4099
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 dont have any issues. but according to some norms in the review I am not supposed to use this file direclty in the header file .. but its fine if i use that inside the corresponding file. To avoid compiler error, i forward declared the structure...
2
2099
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 entire program has 6 files: projecto.h
6
3029
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 I have two classes that I've managed to dodge around this problem for a while, but now I need the include in both classes. This wasn't a problem until now, when I'm trying to declare an stl map with a structure as a data type.
17
2461
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 structure that is only needed by the implementation, so it were declared in the .cpp file, as well. Now, when converting this into a class, the class definition exists in the .h file, since it's required by the interface. The implementation...
0
8227
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8165
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8670
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8613
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8326
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6106
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5561
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1778
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.