Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #102904
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: C declarations |
| Date | 2017-02-01 13:55 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <o6slob$pkf$1@dont-email.me> (permalink) |
| References | (3 earlier) <efd881FhgsiU1@mid.individual.net> <3fd6c360-cd60-4d22-b7c6-4ac75ab206c3@googlegroups.com> <efdemaFhgsiU2@mid.individual.net> <o6s8i9$cuj$1@dont-email.me> <o6sha6$a6l$1@dont-email.me> |
On 01/02/17 12:39, BartC wrote:
> On 01/02/2017 09:10, David Brown wrote:
>> On 01/02/17 07:48, Ian Collins wrote:
>
>>>>> Care to name and shame?
>
> The ones that gave warnings without any extra options were Pelles C,
> lccwin, and gcc. The other three that said nothing nothing were DMC,
> Tiny C and MSVC-2008.
>
>>> Even unadorned gcc complains...
>
> It doesn't complain very strongly. I couldn't see from the grammar of
> any C version that 'a=10;' was legal outside of a function.
>
>> It all depends on what Bart means by "compiles fine". Unadorned gcc
>> will happily compile:
>>
>> a = 10, b = 20, c = 30;
>>
>> int main(void) { }
>>
>> It /will/ give a warning "data definition has no type or storage class",
>> but it will compile the code just as though the missing "int" was there.
>> I can't find any way to turn off the warning, which is probably a good
>> thing.
>
> The problem is this, if you are trying to implement such a parser: do
> you deal with this strictly according to the grammar (and disallow it
> completely)? That sounds a good idea, but then it will reject code that
> will be passed by most other compilers with little problem.
>
It is fine to reject something that the grammar does not allow. It is
also fine to require code that is compatible with modern standards (C99
onwards). It is not unreasonable to consider accepting something
outside the grammar if it is in common use, supported by other tools,
and it would annoy your users if were /not/ supported by your tool.
However, I really can't see that applying in this case.
> However, the grammar also seems to allow these:
>
> const const const a; // no initial value
> int int int b;
>
> gcc allows the first (but 'implicit int'), and disallows the second
> (more than one type specifier).
>
> (It seems crazy to me that a grammar could be so sloppy and ambiguous,
> requiring masses of notes to clarify what is legal and what isn't. And I
> couldn't even find the notes pertaining to the int int int; I have to
> rely on trial and error using a well-regarded compiler (gcc).
>
> It's so easy to get right. Although C's untidy scheme where 'int' and
> 'long' are both independent type-specs, but 'long' can also be a
> modifier to 'int', doesn't help. And 'int static const unsigned const
> long const long volatile' is legal... What a language!)
>
Section 6.7.2 of N1570 (C11 draft) seems reasonably clear to me. "int
int" is not allowed - you can have /one/ list of type specifier from the
list given under "constraints".
On the other had, it is perfectly reasonable to allow more than one
"const" or other type qualifier in the same declaration - this allows
you to have "typedef const char cchar;" and then "const cchar c = 'a';".
Again, it is clear in the standards - section 6.7.3.
If you have been reading Annex A "(Informative) Language syntax summary"
and assuming that the BNF grammar covered all the details, you are bound
to make this sort of mistake. You have to read the actual standards to
see all the constraints - there is a reason why Annex A is labelled
"Informative".
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C declarations BartC <bc@freeuk.com> - 2017-01-30 13:00 +0000
Re: C declarations David Brown <david.brown@hesbynett.no> - 2017-01-30 14:25 +0100
Re: C declarations Keith Thompson <kst-u@mib.org> - 2017-01-30 11:42 -0800
Re: C declarations Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-01-31 13:46 -0800
Re: C declarations BartC <bc@freeuk.com> - 2017-01-31 22:13 +0000
Re: C declarations Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-01-31 16:43 -0800
Re: C declarations Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-01-31 17:06 -0800
Re: C declarations Ian Collins <ian-news@hotmail.com> - 2017-02-01 17:58 +1300
Re: C declarations luser droog <luser.droog@gmail.com> - 2017-01-31 22:42 -0800
Re: C declarations Ian Collins <ian-news@hotmail.com> - 2017-02-01 19:48 +1300
Re: C declarations Robert Wessel <robertwessel2@yahoo.com> - 2017-02-01 01:18 -0600
Re: C declarations David Brown <david.brown@hesbynett.no> - 2017-02-01 10:10 +0100
Re: C declarations BartC <bc@freeuk.com> - 2017-02-01 11:39 +0000
Re: C declarations David Brown <david.brown@hesbynett.no> - 2017-02-01 13:55 +0100
Re: C declarations BartC <bc@freeuk.com> - 2017-02-01 13:22 +0000
Re: C declarations David Brown <david.brown@hesbynett.no> - 2017-02-01 16:30 +0100
Re: C declarations Keith Thompson <kst-u@mib.org> - 2017-02-01 08:15 -0800
Re: C declarations supercat@casperkitty.com - 2017-02-01 08:44 -0800
Re: C declarations David Brown <david.brown@hesbynett.no> - 2017-02-01 20:56 +0100
Re: C declarations supercat@casperkitty.com - 2017-02-01 08:29 -0800
Re: C declarations BartC <bc@freeuk.com> - 2017-02-01 17:24 +0000
Re: C declarations fir <profesor.fir@gmail.com> - 2017-02-01 09:55 -0800
Re: C declarations BartC <bc@freeuk.com> - 2017-02-01 18:44 +0000
Re: C declarations Keith Thompson <kst-u@mib.org> - 2017-02-01 11:03 -0800
Re: C declarations fir <profesor.fir@gmail.com> - 2017-02-01 12:26 -0800
Re: C declarations fir <profesor.fir@gmail.com> - 2017-02-01 13:03 -0800
Re: C declarations fir <profesor.fir@gmail.com> - 2017-02-01 13:12 -0800
Re: C declarations fir <profesor.fir@gmail.com> - 2017-02-03 16:07 -0800
Re: C declarations Keith Thompson <kst-u@mib.org> - 2017-02-01 10:44 -0800
Re: C declarations jameskuyper@verizon.net - 2017-02-01 11:08 -0800
Re: C declarations Keith Thompson <kst-u@mib.org> - 2017-02-01 10:40 -0800
Re: C declarations BartC <bc@freeuk.com> - 2017-02-01 17:04 +0000
Re: C declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-01 19:58 +0000
Re: C declarations BartC <bc@freeuk.com> - 2017-02-01 21:23 +0000
Re: C declarations Keith Thompson <kst-u@mib.org> - 2017-02-01 08:08 -0800
Re: C declarations Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-02-01 12:45 -0800
Re: C declarations Andrey Tarasevich <andreytarasevich@hotmail.com> - 2017-03-06 11:19 -0800
Re: C declarations Keith Thompson <kst-u@mib.org> - 2017-03-06 11:27 -0800
csiph-web