Undetected error in array declarations...
Mike Simons
msimons@fsimons01.erols.com
Thu Dec 3 09:05:00 GMT 1998
Thanks for the speedy reply...
Alexandre Oliva <oliva@dcc.unicamp.br>, 03 Dec 1998 10:29:03 -0200:
>On Dec 2, 1998, Mike Simons <msimons@fsimons01.erols.com> wrote:
>> If a function call is given as a array size,
>
>> I think the compiler should flag this as an error... or if for some reason
>> that may be valid syntax, at the very least issue a warning when -Wall is on.
>
>Try -pedantic. This is a gcc extension.
Sorry for the false bug report...
I "knew" that variable sized arrays were illegal. I "knew" that
array sizes had to be know at compile time. I was surprised when
I saw some code using this and that it worked, and shocked that it
wasn't even a warning with powerful "-Wall -W". ;)
This isn't a invalid, in the GNU dialect of C.
I read around the egcs/gcc info pages and now understand that the
'-Wall -W' combo doesn't actually issue warnings for _ANSI_ C problems...
or even portability issues, I thought it did. I also thought that
variable sized arrays are a "danger", and they are, only if used
badly (but so is everything else) or in code that needs to compiler
independent. I may start using them in the future.
To get as close as possible to ANSI in addition to most useful
warnings, the correct flags would be "-Wall -W -pedantic -ansi".
However, I think there is a bug in this attitude:
(from the info pages, Node: Warning Options)
: Some users try to use `-pedantic' to check programs for strict ANSI
: C conformance. They soon find that it does not do quite what they
: want: it finds some non-ANSI practices, but not all--only those
: for which ANSI C *requires* a diagnostic.
:
: A feature to report any failure to conform to ANSI C might be
: useful in some instances, but would require considerable
: additional work and would be quite different from `-pedantic'. We
: recommend, rather, that users take advantage of the extensions of
: GNU C and disregard the limitations of other compilers. Aside
: from certain supercomputers and obsolete small machines, there is
: less and less reason ever to use any other C compiler other than
: for bootstrapping GNU CC.
To a certain extent I think the attitude "take advantage of our
extensions and disregard other products" is bad. The second paragraph
sounds very close to "embrace, extend, extinguish" but from a very
different source (using public standards (ANSI C), adding extensions,
encouraging users to rely on the extensions ;). Standards are good,
extensions are dangerous but only when they can not be disabled.
While variable sized arrays can be flagged as a warning or error,
that excerpt says to me, that there are extensions have no warnings,
that can not be disabled, and the combination of these is not considered
a problem. I think that extensions that silently creep in are evil.
I think there should be an easy option to force ANSI compliance
and disable all GNU extensions, or at the very least issue a warning
about any extensions in use. So that people who choose to (for whatever
reason) have the option to detect problems. But I don't have the
knowledge to add this option, and I doubt many people who do see any
value in it.
Just my opinion,
Mike Simons
More information about the Gcc-bugs
mailing list