Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #102890
| From | Andrey Tarasevich <andreytarasevich@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: C declarations |
| Date | 2017-01-31 16:43 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <o6ras7$845$1@dont-email.me> (permalink) |
| References | <o6nd9u$rp1$1@dont-email.me> <o6r0gj$4di$1@dont-email.me> <o6r22b$ab3$1@dont-email.me> |
On 1/31/2017 2:13 PM, BartC wrote:
>>
>> I can't say for sure if this was OK in K&R, but in the standard C (even
>> in the first C89/90) this is already illegal. The grammar for
>> _declaration_ requires at least a storage class specifier, a
>> type-specifier or a type qualifier to be present. Which means that if
>> you wanted to take advantage of the "implicit int" rule in C89/90, you'd
>> have to do at least
>>
>> static a = 10, b = 20, c = 30;
>>
>> or, say,
>>
>> const a = 10, b = 20, c = 30;
>>
>> What you have in your original code is not compliant with C89/90
>> requirements.
>
> Out of six compilers, three gave a warning about an implicit int,
It is already perfectly enough. With C compilers, it is generally your
responsibility to tell "mere warnings" from "warnings" that indicate
constraint violations (i.e. "errors").
> the
> other three said nothing at all. That doesn't suggest to me that they
> consider there to be anything much wrong with it.
I wonder what those compilers might be.
I quick experiment with GCC and Clang in `-pedantic-errors` mode shows
them to report an error
error: data definition has no type or storage class
and
error: declaration specifier missing, defaulting to 'int'
respectively.
I was unable to force MSVC to generate an "error", but their warning
message was clear
warning C4218: nonstandard extension used: must specify at least a
storage class or a type
> All six compilers report an error (not a warning) when the same code is
> inside a function. (Undeclared identifier.)
Distinction between "errors" and "warnings" says absolutely nothing
about the validity of the code in such compilers as GCC and Clang. You
have to use `-pedantic-errors` mode to make these compilers to report
all constraint-violation-related "warnings" (and only such "warnings")
as "errors". It is still not perfect, but it works most of the time.
As you already noticed, most C compilers in existence would allow you to do
int *p = 10;
That does not mean that this is a valid C initialization.
These compilers are still trying to be compatible with legacy K&R code.
--
Best regards,
Andrey Tarasevich
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