473,657 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What would be the right warning/error?

Consider this code

static typedef struct {
int boo;
} FOO;

This provokes with MSVC:
------------------------------
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

tstruct.c
tstruct.c(1) : error C2159: more than one storage class specified
------------------------------

With gcc we have:
----------------------------
root@ubuntu-vm:/tmp# gcc t.c
t.c:1: error: multiple storage classes in declaration specifiers
----------------------------

With lcc-win I had
Warning tstruct.c: 1 multiple types in a declaration. Last will be
used: 'typedef'

with lcc-win64
------------------------------
Warning tstruct.c: 1 multiple use of 'typedef'
------------------------------

All those warnings are misleading in my opinion. I have changed the
wording to:
Warning tstruct.c: 1 typedefs can't be static. Static keyword ignored

I think that this is much more clear but I have now some doubts:

Is this true?

My reasoning is that the static keyword can only apply to an
object, and a typedef is not an object. (Obviously there is
another obscure meaning to "static". Let's leave that for now)

Another problem is that both msvc and gcc say something about
"multiple storage classes" that I can't understand. Why that?

Note too that lcc-win issues just a warning. The other two issue
an error and compilation fails. Is this such a bad error that
warrants a failure to compiler the code?
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jun 27 '08 #1
20 3242

"jacob navia" <ja***@nospam.c omwrote in message
news:g2******** **@aioe.org...
Consider this code

static typedef struct {
int boo;
} FOO;

This provokes with MSVC:
------------------------------
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

tstruct.c
tstruct.c(1) : error C2159: more than one storage class specified
Another problem is that both msvc and gcc say something about
"multiple storage classes" that I can't understand. Why that?
I think that typedef is itself considered a storage class specifier (like
static), for purposes of syntax. And presumably you're only allowed one at a
time:

static int *a[10]; /* declares a variable a with static storage */
typedef int *b[10]; /* declares a type alias b */
--
Bartc
Jun 27 '08 #2
On Jun 6, 8:09 am, jacob navia <ja...@nospam.c omwrote:
Consider this code

static typedef struct {
int boo;

} FOO;

This provokes with MSVC:
------------------------------
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

tstruct.c
tstruct.c(1) : error C2159: more than one storage class specified
------------------------------

With gcc we have:
----------------------------
root@ubuntu-vm:/tmp# gcc t.c
t.c:1: error: multiple storage classes in declaration specifiers
----------------------------

With lcc-win I had
Warning tstruct.c: 1 multiple types in a declaration. Last will be
used: 'typedef'

with lcc-win64
------------------------------
Warning tstruct.c: 1 multiple use of 'typedef'
------------------------------

All those warnings are misleading in my opinion. I have changed the
wording to:
Warning tstruct.c: 1 typedefs can't be static. Static keyword ignored

I think that this is much more clear but I have now some doubts:

Is this true?
Is what true? That the warnings are misleading? Well, "uninformat ive"
perhaps. That your warning is more explicit? Sure, okay. That typedefs
can't be static? Yes.
My reasoning is that the static keyword can only apply to an
object, and a typedef is not an object. (Obviously there is
another obscure meaning to "static". Let's leave that for now)

Another problem is that both msvc and gcc say something about
"multiple storage classes" that I can't understand. Why that?
I'm no compiler writer, but I'm guessing it's just the way the
compiler parses the code. "typedef" isn't a storage class (I don't
think <duck>), but it's certainly not a type either, which is what
would otherwise be required after that "static". I've seen many
compiler errors and warnings that are _far_ more obscure than this.
Note too that lcc-win issues just a warning. The other two issue
an error and compilation fails. Is this such a bad error that
warrants a failure to compiler the code?
Unless, as an extension, you document that construct to mean something
useful, I see no reason to allow the code to compile. It's almost
meaningless as it stands, won't compile on at least a couple of other
mainstream compilers, and is so simply fixed that a hard error seems
appropriate to me.

--

Cris
Jun 27 '08 #3
On Jun 6, 8:44 am, crisgoo...@telu s.net wrote:
On Jun 6, 8:09 am, jacob navia <ja...@nospam.c omwrote:
Consider this code
static typedef struct {
int boo;
} FOO;
This provokes with MSVC:
------------------------------
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
tstruct.c
tstruct.c(1) : error C2159: more than one storage class specified
------------------------------
With gcc we have:
----------------------------
root@ubuntu-vm:/tmp# gcc t.c
t.c:1: error: multiple storage classes in declaration specifiers
----------------------------
With lcc-win I had
Warning tstruct.c: 1 multiple types in a declaration. Last will be
used: 'typedef'
with lcc-win64
------------------------------
Warning tstruct.c: 1 multiple use of 'typedef'
------------------------------
<snip>
Another problem is that both msvc and gcc say something about
"multiple storage classes" that I can't understand. Why that?

I'm no compiler writer, but I'm guessing it's just the way the
compiler parses the code. "typedef" isn't a storage class (I don't
think <duck>),
<snip>

Oops, and thirty seconds after posting, I look it up, and lo and
behold, "typedef" _is_ a storage class specifier ...

Sigh.

--

Cris
Jun 27 '08 #4
[My posts via rr.com still aren't showing up on aioe.org, so I'm
posting this through aioe.org so jacob can see it. I'm continuing
to post most of my articles through rr.com]

jacob navia <ja***@nospam.c omwrites:
Consider this code

static typedef struct {
int boo;
} FOO;

This provokes with MSVC:
------------------------------
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

tstruct.c
tstruct.c(1) : error C2159: more than one storage class specified
------------------------------

With gcc we have:
----------------------------
root@ubuntu-vm:/tmp# gcc t.c
t.c:1: error: multiple storage classes in declaration specifiers
----------------------------
Both of those seem reasonable.
With lcc-win I had
Warning tstruct.c: 1 multiple types in a declaration. Last will be
used: 'typedef'

with lcc-win64
------------------------------
Warning tstruct.c: 1 multiple use of 'typedef'
------------------------------

All those warnings are misleading in my opinion. I have changed the
wording to:
Warning tstruct.c: 1 typedefs can't be static. Static keyword ignored

I think that this is much more clear but I have now some doubts:

Is this true?
The warning is correct, as far as it goes, but the fact that your
diagnostic *doesn't* refer to multiple storage classes makes me
concerned that you might be missing some other cases.
My reasoning is that the static keyword can only apply to an
object, and a typedef is not an object. (Obviously there is
another obscure meaning to "static". Let's leave that for now)

Another problem is that both msvc and gcc say something about
"multiple storage classes" that I can't understand. Why that?
C99 6.7.1p3:

The typedef specifier is called a storage-class specifier for
syntactic convenience only; it is discussed in 6.7.7.
Note too that lcc-win issues just a warning. The other two issue
an error and compilation fails. Is this such a bad error that
warrants a failure to compiler the code?
Absolutely. Issuing a warning for code with a constraint violation
is, of course, permitted by the standard, but I can't imagine why
you'd want to do so in this case. I see no benefit from allowing the
user to leave this error uncorrected, or in blindly *guessing* that
the last storage class is what was intended.

You apparently treat this:
static typedef int foo;
as a typedef (ignoring "static"), and this:
typedef static int foo;
as a static object declaration. Both are simply errors.

(In another thread, you do something equally arbitrary for type
specifiers.)

--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #5
jacob navia wrote:
Consider this code

static typedef struct {
int boo;
} FOO;

This provokes with MSVC:
------------------------------
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

tstruct.c
tstruct.c(1) : error C2159: more than one storage class specified
------------------------------

With gcc we have:
----------------------------
root@ubuntu-vm:/tmp# gcc t.c
t.c:1: error: multiple storage classes in declaration specifiers
----------------------------

With lcc-win I had
Warning tstruct.c: 1 multiple types in a declaration. Last will be
used: 'typedef'

with lcc-win64
------------------------------
Warning tstruct.c: 1 multiple use of 'typedef'
------------------------------

All those warnings are misleading in my opinion.
The first two seem to me more precise than the latter two,
but I'll grant that they might mislead someone who didn't know
that `typedef' was a storage class. The number of such someones
may be non-negligible, hence the potential to mislead may be
non-negligible.
I have changed the
wording to:
Warning tstruct.c: 1 typedefs can't be static. Static keyword ignored

I think that this is much more clear but I have now some doubts:

Is this true?
It is true that there can be at most one storage class
specifier in a declaration, so you can't have `static typedef'.
Nor can you have `typedef static' or `register typedef' or
`auto extern' or `static register' or ...
Another problem is that both msvc and gcc say something about
"multiple storage classes" that I can't understand. Why that?
Because `typedef' and `extern' and `static' and `auto' and
`register' are the storage-class specifiers (6.7.1). `typedef'
is an oddball (as noted in 6.7.1p3), but it's an s-c specifier
nonetheless.
Note too that lcc-win issues just a warning. The other two issue
an error and compilation fails. Is this such a bad error that
warrants a failure to compiler the code?
Purely a judgment call, with no clearly-defined Right Answer.
A diagnostic is required, but beyond that it's just your notion
of what would be most helpful to the user.

--
Er*********@sun .com

Jun 27 '08 #6
jacob navia wrote:
>
I didn't know that a typedef is a storage class. And now that
the appropiate parts of the standard have been cited I still
do not understand it.

#define FOO 8

the #define is not a storage class.

A typedef is a compile time alias for another type. Why should it
be a storage class?
There are multiple possible answers ...

One answer might be "It's a storage class specifier because
the Standard says so," but that might not satisfy the curious
mind. It's like answering "Why is murder a crime?" with
"Because there's a law against it." Still, on one level it's
the truth, just like "Why does ^ mean exclusive-or instead of
exponentiation? " or "Why is it `struct' and not `record'?"

Probing a little deeper, we see that the Standard itself
says (in normative text, no less) that `typedef' is a storage
class specifier as a matter of convenience. So, what is made
more convenient by this peculiar choice? Well, as you said at
the beginning, `typedef' conflicts with `static' -- and with
`extern' and `auto' and `register', too, and all those four
conflict with each other. So lumping `typedef' in with the
others allows the "one storage class" rule of 6.7.1p2 to be
expressed succinctly. If `typedef' were handled separately,
the rule would have to be something like

At most, one storage-class specifier may be given in
the declaration specifiers in a declaration, except
that if the declaration specifiers include `typedef'
then no storage-class specifier may be given.

And then there's the grammar. `typedef' can appear at all
the same places the "real" storage classes can, and groups with
the other bits of a declaration the same way they do, so it's
convenient to lump them under the same nonterminal. If `typedef'
were handled separately, you'd also need something like

typedef-or-storage-class-specifier:
typedef
storage-class-specifier

storage-class-specifier:
extern
static
auto
register

.... and you'd scratch your head trying to figure out what value
the extra nonterminal brings to the party.

The Rationale doesn't mention the matter, but probing all
the way back to K&R Classic we find "Syntactica lly, typedef is
like the storage classes extern, static, etc." (p. 140), and
we find `typedef' listed among the storage class specifiers
(p. 192), with the same "syntactic convenience" remark that
the Standard uses. So the treatment of `typedef' as a storage
class specifier is not a new aberration; it is at worst a time-
honored aberration. Or "hallowed tradition," as we say in
America when we're running for political office.

--
Er*********@sun .com
Jun 27 '08 #7

"jacob navia" <ja***@nospam.c omschreef in bericht
news:g2******** **@aioe.org...
Consider this code

static typedef struct {
int boo;
} FOO;

This provokes with MSVC:
------------------------------
Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

tstruct.c
tstruct.c(1) : error C2159: more than one storage class specified
------------------------------

With gcc we have:
----------------------------
root@ubuntu-vm:/tmp# gcc t.c
t.c:1: error: multiple storage classes in declaration specifiers
----------------------------

With lcc-win I had
Warning tstruct.c: 1 multiple types in a declaration. Last will be
used: 'typedef'

with lcc-win64
------------------------------
Warning tstruct.c: 1 multiple use of 'typedef'
------------------------------

All those warnings are misleading in my opinion. I have changed the
wording to:
Warning tstruct.c: 1 typedefs can't be static. Static keyword ignored
what if you say
register typedef struct...
or
extern typedef struct...

etc.

I noticed that MSVC compiles the following with no complaints.

const typedef struct {
int boo;
} FOO;

Is that correct?

Jun 27 '08 #8
In article <1212768389.979 717@news1nwk>,
Eric Sosman <Er*********@su n.comwrote:
It is true that there can be at most one storage class
specifier in a declaration, so you can't have `static typedef'.
I think Jacob is right to try to give a more specific error message in
this case. "typedef" may be a storage class as far as the standard is
concerned, but that's just the standard-writer's trick for terseness,
and an error message has other goals.

-- Richard
--
In the selection of the two characters immediately succeeding the numeral 9,
consideration shall be given to their replacement by the graphics 10 and 11 to
facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)
Jun 27 '08 #9
CBFalconer said:
jacob navia wrote:
>>
... snip ...
>>
#define FOO 8

the #define is not a storage class.

A typedef is a compile time alias for another type. Why should it
be a storage class?

#define p1 int*
typedef p2 int*;

p1 a1, b1;
p2 a2, b2;

note that a1, a2, and b2 are pointers. b1 is an int object.
Note that typedef p2 int*; is a syntax error, and neither a2 nor b2 have
any meaning whatsoever.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2961
by: fastwings | last post by:
mm the code //////makemenu.h//// class menu { public: int op; pmenu(int op,int sub = 0) { switch op {
3
2046
by: nick | last post by:
i have 5 files,when i use make command to compile them a error occurs "make: Warning: Infinite loop: Target `c.o' depends on itself" when i type make an warning message occurs cc -c b.c cc -c a.c make: Warning: Infinite loop: Target `c.o' depends on itself cc -c c.c cc b.o a.o c.o -o a
26
4460
by: Lasse Edsvik | last post by:
Hello I'm trying to build a simple COM+ app in vs.net using C# and i cant register it in component manager..... what more is needed than this: using System; using System.EnterpriseServices;
669
25859
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
2
2749
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include <string>
4
3761
by: d3vkit | last post by:
Okay so I am at a loss here. I have a website that I've previously had no trouble connecting to the mysql DB on. I have an include to a connect file with the relevant connection info, and it was working fine until today. I am trying to implement some ajax with the javascript framework mootools (although I don't see how this is causing the problem it started happening right around this time sooo...) I am sending info from my login form to the...
1
5725
by: dewi | last post by:
Dear All, I am trying to compile a C code using Visual C++. Can anyone explain how to solve it? Thank You. #include <math.h> #include <string.h> #include "RV2AJFRONT_NEW.h" #include "RV2AJFRONT_NEW_private.h"
5
1977
by: Vols | last post by:
class A{ public: int x; }; class B : public A{ public: int y; }; void foo()
46
2112
by: Kenny O'Clock | last post by:
This came up in a job interview, what is the output of the program below? I tried to compile and run it myself, but my compiler (lcc-win32) aborts with this errors.... Warning test2.c: 3 old-style function definition for 'main' Warning test2.c: 3 missing prototype for 'main' Warning test2.c: 3 ' Error test2.c: 3 compiler error in d:\lcc\mc71\types.c--assertion failure at line 868 Error c:\test\test2.c 3 Compiler error (trap)....
0
8413
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
8324
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
8842
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
8740
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
8513
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,...
0
7352
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5642
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();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.