In the book "C A reference Manual" (5th edition), the authors state
that a declaration like the following is invalid:
static struct s { int a; int b; } ;
I can't find in the standard which constraint or semantics is
violated.
Can you help?
|
|
0
|
|
|
|
Reply
|
Luca
|
8/1/2010 3:48:31 PM |
|
Luca Forlizzi wrote:
> In the book "C A reference Manual" (5th edition), the authors state
> that a declaration like the following is invalid:
>
> static struct s { int a; int b; } ;
>
> I can't find in the standard which constraint or semantics is
> violated.
> Can you help?
'static' should be applied to declarations with declarators.
You are just declaring a 'tag', not a variable of type struct,
so it has not sense to apply a storage class specifier
--
Vincenzo Mercuri
|
|
0
|
|
|
|
Reply
|
Vincenzo
|
8/1/2010 3:55:49 PM
|
|
Vincenzo Mercuri wrote:
> so it has not sense [...]
sorry, i meant 'it makes no sense'
--
Vincenzo Mercuri
|
|
0
|
|
|
|
Reply
|
Vincenzo
|
8/1/2010 3:59:23 PM
|
|
On 1 Ago, 17:59, Vincenzo Mercuri <c...@lang.c> wrote:
> Vincenzo Mercuri wrote:
> > so it has not sense [...]
>
> sorry, i meant 'it makes no sense'
>
> --
> Vincenzo Mercuri
I agree that it makes no sense, but how one concludes that it is
invalid?
|
|
0
|
|
|
|
Reply
|
Luca
|
8/1/2010 4:08:59 PM
|
|
Luca Forlizzi <luca.forlizzi@gmail.com> writes:
> In the book "C A reference Manual" (5th edition), the authors state
> that a declaration like the following is invalid:
>
> static struct s { int a; int b; } ;
>
> I can't find in the standard which constraint or semantics is
> violated.
> Can you help?
My best understanding is that it is legal and well-defined.
Certainly it's legal and well-defined without the 'static'
storage-class specifier, and a grep on 'storage.class' didn't
turn up anything wrong that I could see.
|
|
0
|
|
|
|
Reply
|
Tim
|
8/1/2010 4:11:26 PM
|
|
Luca Forlizzi wrote:
> On 1 Ago, 17:59, Vincenzo Mercuri<c...@lang.c> wrote:
>> Vincenzo Mercuri wrote:
>>> so it has not sense [...]
>>
>> sorry, i meant 'it makes no sense'
>>
>> --
>> Vincenzo Mercuri
>
> I agree that it makes no sense, but how one concludes that it is
> invalid?
Beware that 'C: A Reference Manual' says that it is
"nonsensical and (in Standard C) illegal" where Standard C
means C89 (see page 4, 5th edition).
Now I can't say if it is illegal in C89, (i dont have the
Standard) but I can just say it is nonsensical in C99
--
Vincenzo Mercuri
|
|
0
|
|
|
|
Reply
|
Vincenzo
|
8/1/2010 4:23:31 PM
|
|
On 1 Ago, 18:11, Tim Rentsch <t...@alumni.caltech.edu> wrote:
> Luca Forlizzi <luca.forli...@gmail.com> writes:
> > In the book "C A reference Manual" (5th edition), the authors state
> > that a declaration like the following is invalid:
>
> > static struct s { int a; int b; } =A0 ;
>
> > I can't find in the standard which constraint or semantics is
> > violated.
> > Can you help?
>
> My best understanding is that it is legal and well-defined.
> Certainly it's legal and well-defined without the 'static'
> storage-class specifier, and a grep on 'storage.class' didn't
> turn up anything wrong that I could see.
that's also my understanding. I also think that the presence of
'static' has no effect on the semantics of the declaration (as
suggested by the book authors). Do you agree?
|
|
0
|
|
|
|
Reply
|
Luca
|
8/1/2010 4:54:50 PM
|
|
On 1 Ago, 18:23, Vincenzo Mercuri <c...@lang.c> wrote:
> Luca Forlizzi wrote:
> > On 1 Ago, 17:59, Vincenzo Mercuri<c...@lang.c> =A0wrote:
> >> Vincenzo Mercuri wrote:
> >>> so it has not sense [...]
>
> >> sorry, i meant 'it makes no sense'
>
> >> --
> >> Vincenzo Mercuri
>
> > I agree that it makes no sense, but how one concludes that it is
> > invalid?
>
> Beware that 'C: A Reference Manual' says that it is
> "nonsensical and (in Standard C) illegal" where Standard C
> means C89 (see page 4, 5th edition).
> Now I can't say if it is illegal in C89, (i dont have the
> Standard) but I can just say it is nonsensical in C99
>
> --
> Vincenzo Mercuri
Hi Vincenzo,
I checked C89 and I don't see in it anything that renders such a
declaration invalid. I think it is valid and a well-defined
declaration.
And that it has a meaning, because it declares the new struct type and
its tag.
Because of that, I wouldn't call it nonsensical. The only
"nonsensical" part, is that it uses a storage-class specifier that
could be omitted without changing the declaration's meaning. There are
cases like this. For instance in
extern int f(void);
the storage-class specifier could be omitted without changing
semantics, as well (so I think).
Would you call it nonsensical, too ?
|
|
0
|
|
|
|
Reply
|
Luca
|
8/2/2010 1:47:30 PM
|
|
Luca Forlizzi wrote:
> On 1 Ago, 18:23, Vincenzo Mercuri<c...@lang.c> wrote:
>> Luca Forlizzi wrote:
>>> On 1 Ago, 17:59, Vincenzo Mercuri<c...@lang.c> wrote:
>>>> Vincenzo Mercuri wrote:
>>>>> so it has not sense [...]
>>
>>>> sorry, i meant 'it makes no sense'
>>
>>>> --
>>>> Vincenzo Mercuri
>>
>>> I agree that it makes no sense, but how one concludes that it is
>>> invalid?
>>
>> Beware that 'C: A Reference Manual' says that it is
>> "nonsensical and (in Standard C) illegal" where Standard C
>> means C89 (see page 4, 5th edition).
>> Now I can't say if it is illegal in C89, (i dont have the
>> Standard) but I can just say it is nonsensical in C99
>>
>> --
>> Vincenzo Mercuri
>
> Hi Vincenzo,
>
> I checked C89 and I don't see in it anything that renders such a
> declaration invalid. I think it is valid and a well-defined
> declaration.
> And that it has a meaning, because it declares the new struct type and
> its tag.
> Because of that, I wouldn't call it nonsensical. The only
> "nonsensical" part, is that it uses a storage-class specifier that
> could be omitted without changing the declaration's meaning. There are
> cases like this. For instance in
>
> extern int f(void);
>
> the storage-class specifier could be omitted without changing
> semantics, as well (so I think).
> Would you call it nonsensical, too ?
Hi Luca,
...I think I got your point. My answer is: no, I wouldn't call it
'nonsensical' and I'm going to tell you why. The 'extern' storage-class
specifier is unnecessary in function prototype declarations, but
unnecessary doesn't mean nonsensical. For some programmers it's
just good style. Something different happens with:
static struct s { int a; int b; };
here the problem is that the storage-class specifier will be ignored
by the compiler (see H&S pag 89) -- gcc warns you: 'useless storage
class specifier in empty declaration'.
Again, as H&S says:
"you might think that a later declaration of the form":
struct s x, y;
"will cause x and y to have the storage class static. It will not."
--
Vincenzo Mercuri
|
|
0
|
|
|
|
Reply
|
Vincenzo
|
8/2/2010 4:30:46 PM
|
|
Luca Forlizzi <luca.forlizzi@gmail.com> writes:
> On 1 Ago, 18:11, Tim Rentsch <t...@alumni.caltech.edu> wrote:
>> Luca Forlizzi <luca.forli...@gmail.com> writes:
>> > In the book "C A reference Manual" (5th edition), the authors state
>> > that a declaration like the following is invalid:
>>
>> > static struct s { int a; int b; } ;
>>
>> > I can't find in the standard which constraint or semantics is
>> > violated.
>> > Can you help?
>>
>> My best understanding is that it is legal and well-defined.
>> Certainly it's legal and well-defined without the 'static'
>> storage-class specifier, and a grep on 'storage.class' didn't
>> turn up anything wrong that I could see.
>
> that's also my understanding. I also think that the presence of
> 'static' has no effect on the semantics of the declaration (as
> suggested by the book authors). Do you agree?
Yes, reading the relevant sections (6.2.2 and 6.2.4, IIRC), makes
it clear that the result is not changed by adding 'static'.
|
|
0
|
|
|
|
Reply
|
Tim
|
8/4/2010 6:27:03 PM
|
|
On Aug 4, 2:27=A0pm, Tim Rentsch <t...@alumni.caltech.edu> wrote:
> Luca Forlizzi <luca.forli...@gmail.com> writes:
> > On 1 Ago, 18:11, Tim Rentsch <t...@alumni.caltech.edu> wrote:
> >> Luca Forlizzi <luca.forli...@gmail.com> writes:
> >> > In the book "C A reference Manual" (5th edition), the authors state
> >> > that a declaration like the following is invalid:
>
> >> > static struct s { int a; int b; } =A0 ;
>
> >> > I can't find in the standard which constraint or semantics is
> >> > violated.
> >> > Can you help?
>
> >> My best understanding is that it is legal and well-defined.
> >> Certainly it's legal and well-defined without the 'static'
> >> storage-class specifier, and a grep on 'storage.class' didn't
> >> turn up anything wrong that I could see.
>
> > that's also my understanding. I also think that the presence of
> > 'static' has no effect on the semantics of the declaration (as
> > suggested by the book authors). Do you agree?
>
> Yes, reading the relevant sections (6.2.2 and 6.2.4, IIRC), makes
> it clear that the result is not changed by adding 'static'.
Agreed. Functions and objects have linkage. Objects have storage
duration. A 'struct' tag has neither of these, but "storage class
specifier" in the syntax is (ab)used to include 'typedef'. One might
wish to use 'typedef' along with their 'struct' declaration.
|
|
0
|
|
|
|
Reply
|
Shao
|
8/5/2010 5:53:09 PM
|
|
|
10 Replies
505 Views
(page loaded in 0.132 seconds)
Similiar Articles: signed/unsigned as fundamental types - comp.lang.c++.moderated ...I know that it's just syntactic sugar ... Some sort of traits class solves it > for both. //Warning: _not_ C++ type_modifier ... you make signed/unsigned specifiers ... logrotate for HP-UX 11.31 Itanium - comp.sys.hp.hpux... 59: warning: return type defaults ... 59: error: expected declaration specifiers before 'logs' logrotate.h:61: error: storage class ... >>> >>> >> If it's just for renaming ... bit fields and default initialization - comp.lang.c++.moderated ...Notice, however, that any POD with static storage ... this > well, but if not then lets make my_class not a POD type ... as above: the value is undefined if the declaration ... header's included but still get 'implicit declaration' - comp.unix ...... and getting: storage size of `act' isn't known warning: implicit declaration of ... in your code just before ... include a ... the type in a separate type declaration ... Micro Focus Net Express 5.0 - comp.lang.cobolI just tried the example "pclass.app" in the ... Let's say I have a class with a working-storage item defined as: 01 ... Much less typing, perfectly readable, and much ... Some text processing questions - comp.lang.vhdl... paranoia result(1 to N) := L.all; --- storage ... above might not be at all applicable, they are just ... This doesn't work because I can't make a type declaration of ... Copying rows in a two dimensional array. - comp.lang.ada ...I make just as many mistakes with slices ... Type (<>) is private; -- The type must be initialized at declaration ... pragma Inline (Last_Column); type Storage ... 32 bit applet on 64 bit Java? - comp.lang.java.programmer ...Hmmm, just because it's worked up to now ... way to go should be to put the java type to long and the C jint to jlong (__int64)? C style question - comp.lang.c... is legal, but > "unsigned long int" (or just ... you need > <stdio.h> to get the correct declaration for type FILE. ... as C-style FUNCTIONS that use those basic classes? Converting number to std::string ("itoa()" ) - comp.lang.c++ ...... to convert ascii to int you just need storage for an int and that is of a size known to the compiler and a function whose declaration ... from using a genuine string type ... Storage Class - Microsoft Corporation: Software, Smartphones ...storage-class-specifier declaration-specifiers opt. type-specifier declaration-specifiers opt. type-qualifier declaration-specifiers opt. storage-class-specifier: /* For ... Storage Class (C) - Microsoft Corporation: Software, Smartphones ...declaration-specifiers: storage-class-specifier declaration-specifiers opt type-specifier declaration-specifiers opt type-qualifier declaration-specifiers opt 7/24/2012 5:15:42 AM
|