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. 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
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
|
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...
|
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 :
|
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?
|
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
| |
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...
|
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
|
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.
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
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();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |