Re: enums and switch vs function calls

Liste des GroupesRevenir à cl c 
Sujet : Re: enums and switch vs function calls
De : ben (at) *nospam* bsb.me.uk (Ben Bacarisse)
Groupes : comp.lang.c
Date : 25. Apr 2025, 01:12:22
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87bjslhzfd.fsf@bsb.me.uk>
References : 1 2 3 4 5
User-Agent : Gnus/5.13 (Gnus v5.13)
scott@slp53.sl.home (Scott Lurndal) writes:

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
>
ram@zedat.fu-berlin.de (Stefan Ram) writes:
>
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
>
That example exemplifies the seriously screwed up error reporting in the
gnu compiler collection.
>
One line of informative error message followed by 5 lines of useless
cruft to wade through.  And no way to turn it off completely.
>
That's true, but it can be reduced to only two lines total (so only one
line more than needed), by using -fno-diagnostics-show-caret.
>
Yes, I use that.  I still find that the "note:" lines clutter the
output and provide zero benefit.

Does

  gcc -fcompare-debug-second -fno-diagnostics-show-caret

do what you want?  The behaviour seems to be a side effect of some
internal debug options so it probably can't be relied upon long-term.

--
Ben.

Date Sujet#  Auteur
5 Apr 25 * enums and switch vs function calls12Richard Harnden
5 Apr 25 +* Re: enums and switch vs function calls9Stefan Ram
5 Apr 25 i+- Re: enums and switch vs function calls1David Brown
5 Apr 25 i+- Re: enums and switch vs function calls1Stefan Ram
6 Apr 25 i`* Re: enums and switch vs function calls6Tim Rentsch
6 Apr 25 i +- Re: enums and switch vs function calls1David Brown
7 Apr 25 i +- Re: enums and switch vs function calls1Tim Rentsch
25 Apr 25 i `* Re: enums and switch vs function calls3Ben Bacarisse
25 Apr 25 i  `* Re: enums and switch vs function calls2Ben Bacarisse
4 May 25 i   `- Re: enums and switch vs function calls1Tim Rentsch
5 Apr 25 `* Re: enums and switch vs function calls2Thiago Adams
6 Apr 25  `- Re: enums and switch vs function calls1David Brown

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal