This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Warning about int<-->enum conversions?
- From: "Gabriel Dos Reis" <gdr at acm dot org>
- To: "Robert Dewar" <dewar at gnat dot com>
- Cc: dewar at gnat dot com, gdr at acm dot org, gcc at gcc dot gnu dot org,giovannibajo at libero dot it
- Date: Thu, 8 Jul 2004 16:41:00 +0200 (CEST)
- Subject: Re: Warning about int<-->enum conversions?
- References: <20040708142931.CB6B1F2EBC@nile.gnat.com>
- Reply-to: gdr at acm dot org
You Wrote Robert Dewar
>> For most C codes, it would be a real disaster. C definitely
>> has a differrent view from Ada (and C programmers seem
>> to have a different view). Turn that on warning and bootstrap
>> GCC's own source code, that will give you an idea ;-)
>
> Most definitely I would think of this as a warning that was off
> by default, and not included in -Wall. But you have at least one
> datapoint of a C programmer who would like this warning :-)
Yes, but he just remains to be corrupted into thinking of
"idiomatic C" :-)
(This is a recurrent theme for C++ who has tried to improve
over the C situation. In C, you can have both implicit
conversions. C++ says that you can't go from int to enums
implicitly -- a first step to have proper behaving enums.
Some people firmly believe that C is right and it is an endless
source of complains, because most C programs (and headers!)
just think of enums and ints as interchangeable. And I can't blame
them. The language definition does everything in that
direction. I don't even imagine what would happen if every
use of enums in context of integers should be decorated
by an explicit cast)
A warning is useful to have in the compiler (even if off by default)
if it proves to be useful for enough situations and people.