Re: Enum type check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



keshav yadav <keshav.yadav2005@xxxxxxxxx> writes:

>  Thanks for reply  below the reasion why we are getting the error
> In C, an enum is basically a way to alias names to integers.This does
> not lead to improved type checking. In C++, an enum defines an actual
> type, which results in strong type checking.
> In C++, an integer cannot be assigned directly to an "enum" as it
> could be in C. If your program contains such assignments, first cast
> the integer to the "enum" type, as in the following example:
> for example:-
> int i;
> enum X {a, b, c} e;
> e = i; /* Legal in C, not in C++. */
> e = (enum X)i; // Legal in C++.
>
>    What I want to know is how to catch an error on C code. is there
> any flag in gcc with we can get the same error .

The best you can do today is -Wc++-compat.  Of course that will catch
other kinds of things as well.  There is nothing specific to the enum
case.

Ian


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux