Sujet : Re: enums and switch vs function calls
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.cDate : 05. Apr 2025, 12:26:32
Autres entêtes
Organisation : Stefan Ram
Message-ID : <enum-20250405122329@ram.dialup.fu-berlin.de>
References : 1
Richard Harnden <
richard.nospam@gmail.invalid> wrote or quoted:
int hex = colour_to_hex(10);
... then the compiler doesn't complain that 10 is not in the enum.
Why? Surely the compiler can tell.
I get
|
|error: enum conversion when passing argument 1 of 'colour_to_hex' is invalid in C++ [-Wc++-compat]
| |int hex = colour_to_hex(10);
| | ^~
|note: expected 'enum colour' but argument is of type 'int'
| | int colour_to_hex(enum colour colour)
| | ^~~~~~~~~~~~~
|
with
gcc -Wc++-compat
.