Does a translation unit have to have at least one externally visible
declaration or function definition to be valid? As I read the standard,
it doesn't: it must have at least one declaration or function definition,
but they can be static, extern or even a typedef.
6.9 External definitions
1 translation-unit:
external-declaration
translation-unit external-declaration
external-declaration:
function-definition
declaration
6.9.1 Function definitions
1 function-definition:
declaration-specifiers declarator declaration-list(opt)
compound-statement
6.7 Declarations
1 declaration:
declaration-specifiers init-declarator-listopt ;
declaration-specifiers:
storage-class-specifier declaration-specifiers(opt)
type-specifier declaration-specifiers(opt)
type-qualifier declaration-specifiers(opt)
function-specifier declaration-specifiers(opt)
6.7.1 Storage-class specifiers
1 storage-class-specifier:
typedef
extern
static
auto
register
So as I read the standard a translation unit consisting of only
typedef int fred;
would be valid, and a conforming compiler shouldn't complain about it.
Is this correct, or have I missed something?
Chris C 4 9835
On Tue, 28 Jun 2005 14:09:31 +0100, Chris Croughton wrote:
.... So as I read the standard a translation unit consisting of only
typedef int fred;
would be valid, and a conforming compiler shouldn't complain about it.
Yes, it is valid. However a conforming compiler can complain about
anything it likes. A translation unit with no definition having external
linkage seems to be useless, although correct. It is something that a
compiler could reasonably complain about, as long as it doesn't reject the
program.
Lawrence
On Wed, 29 Jun 2005 13:48:10 +0100, Lawrence Kirby
<lk****@netactive.co.uk> wrote: On Tue, 28 Jun 2005 14:09:31 +0100, Chris Croughton wrote:
...
So as I read the standard a translation unit consisting of only
typedef int fred;
would be valid, and a conforming compiler shouldn't complain about it. Yes, it is valid. However a conforming compiler can complain about anything it likes.
True, it can complain. However, a compiler which complains about legal
programs too much has quality of implementation problems...
A translation unit with no definition having external linkage seems to be useless, although correct. It is something that a compiler could reasonably complain about, as long as it doesn't reject the program.
Well, it's useless to the compiler, not necessarily useless in the
context of a multi-target build system (where parts of the program may
be not needed for a particular build, so they are conditionally compiled
out, as in the cases I'm dealing with).
I've found that having just a 'useless' typedef does indeed shut up the
compilers I'm using (whereas having an unreferenced static identifier
causes them to complain differently). Probably because it can't
complain reasonably about unused typedefs, there are millions of them in
header files...
Chris C
On Thu, 30 Jun 2005 11:47:48 +0100, Chris Croughton wrote: On Wed, 29 Jun 2005 13:48:10 +0100, Lawrence Kirby <lk****@netactive.co.uk> wrote:
On Tue, 28 Jun 2005 14:09:31 +0100, Chris Croughton wrote:
...
So as I read the standard a translation unit consisting of only
typedef int fred;
would be valid, and a conforming compiler shouldn't complain about it. Yes, it is valid. However a conforming compiler can complain about anything it likes.
True, it can complain. However, a compiler which complains about legal programs too much has quality of implementation problems...
Compilers can generate a lot of warnins about technically correct code,
e.g. unused variable warnings. An unusable translation unit isn't an
unreasonable case for a warning. A translation unit with no definition having external linkage seems to be useless, although correct. It is something that a compiler could reasonably complain about, as long as it doesn't reject the program.
Well, it's useless to the compiler, not necessarily useless in the context of a multi-target build system (where parts of the program may be not needed for a particular build, so they are conditionally compiled out, as in the cases I'm dealing with).
Unused variables can occur in similar circumstances. It may be a useful
diagnostic in other circumstances, this is just an argument for being able
to configure what warnings a compiler will generate.
I've found that having just a 'useless' typedef does indeed shut up the compilers I'm using (whereas having an unreferenced static identifier causes them to complain differently). Probably because it can't complain reasonably about unused typedefs, there are millions of them in header files...
Yes, it would be unreasonable to warn about an unused typedef.
Lawrence
In article <sl******************@ccserver.keris.net>,
Chris Croughton <ch***@keristor.net> wrote:
.... Yes, it is valid. However a conforming compiler can complain about anything it likes.
True, it can complain. However, a compiler which complains about legal programs too much has quality of implementation problems...
Yes, but QOI is OT in clc. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Neal |
last post by:
According to the specs
(http://www.w3.org/TR/html401/struct/links.html#h-12.2), the <a> element
requires an end tag. And so, when we use <A NAME="foo"> in HTML 2.0 to
4.01, it won't validate,...
|
by: John Carson |
last post by:
One routinely hears that the order of initialisation of objects with static
storage duration in different translation units cannot in general be
guaranteed. I have a question about one way to...
|
by: Steven T. Hatton |
last post by:
Is there anything that gives a good description of how source code is
converted into a translation unit, then object code, and then linked. I'm
particularly interested in understanding why putting...
|
by: newbiecpp |
last post by:
I am looking for a C++ unit testing program. I googled and found there are
quite a few there, such as CppTest, C++Test, and DejaGnu. Can someone give
me a recommendation among these programs? I...
|
by: Bob |
last post by:
Are they different names for the same concept ?
|
by: napstar |
last post by:
I have a C# program that returns an empty collection and a Unit test that test to see if the name of an element in the empty returned collection is the same as an object I have.I'm asserting that...
|
by: aaragon |
last post by:
Hello everyone,
I have this problem that is driving me crazy! I have a typedef for a
singleton object in a file "fileA.h", then I try to use that object in
"fileB.h" and then the compiler says...
|
by: Tomás Ó hÉilidhe |
last post by:
I have a translation unit which defines a global object:
BEGIN "yellow.c"
int i = 7;
END
I want this object to be accessible from other translation units, so I give
it external linkage....
|
by: gw7rib |
last post by:
If a class has more than one member function, is it possible for the
code for one to be in one translation unit (ie file) and the code for
another to be in a different translation unit? I would...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
| |