This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Warning about int<-->enum conversions?


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]