On 01/30/2013 05:54 PM, BartC wrote:
> "James Kuyper" <> wrote in message
> news:...
>> On 01/30/2013 04:04 PM, BartC wrote:
>
>> dropped the "implicit int" rule. The problem you describe is precisely
>> why that change was made. Have you been compiling for C90?
>
> Probably. I don't use any switches except the handful I know about.
With no switches set, gcc implements Gnu-C, a language closely related
to C, but it does not actually conform to any version of the C standard.
If you didn't set -ansi or -std=c90 or -std-c99 or -std=c9x or -std=c1x,
discussions about how it behaves are more appropriately carried out in a
forum associated with Gnu-C.
>> Doubtless there is some switch somewhere or other on my gcc to change this
>>> behaviour (but it's usually a major undertaking to find out what it might
>>> be).
>
>> -std=c99 -Wall -Wstrict-prototypes -Wmissing-prototypes covers most of
>> the possible issues with function prototypes.
>
> Thanks. Although I found that -std=c99 by itself is sufficient to flag
> 'implicit declarations' of functions. The prototype options didn't seem to
> do anything.
They only have a visible effect if you create the situation that they're
supposed to warn about. I was recommending those options on general
grounds, not because they help with this particular problem.
-Wstrict-prototypes warns about using non-prototyped function
declarations. -Wmissing-prototypes warns if a global function is defined
without a prototype already in scope - this is intended to encourage the
#inclusion of header files containing the prototype in the same file
with the definition, so you can be sure the prototype in the header is
compatible with the definition. It would be better if it checked whether
the prototype was the result of a #include directive, but presumably
that would have been harder to implement.
> One small problem is that c99 mode doesn't like my anonymous unions; it
> gives loads of warnings (and usually my compilations are 'clean'; these
> would drown out any real problems). But my own research came up with
> the -std=gnu99 option which highlights the missing prototype I knew about
> (and a couple of dozen I didn't!), without objecting to much else.
With that option, you're compiling Gnu-C99, not C99. Those are two
different, but related languages. Anonymous unions are a feature of
Gnu-C99 and C2011, but not of C99. Try -std=c1x, and see if you like the
results any better.
--
James Kuyper
|