Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.lang.c > #392119

Re: enums and switch vs function calls

Path csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: enums and switch vs function calls
Date Sun, 06 Apr 2025 03:17:03 -0700
Organization A noiseless patient Spider
Lines 34
Message-ID <86y0wdfvc0.fsf@linuxsc.com> (permalink)
References <vsr0ml$1to9m$1@dont-email.me> <enum-20250405122329@ram.dialup.fu-berlin.de> <1ybIP.1259194$2zn8.458292@fx15.iad>
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Date Sun, 06 Apr 2025 12:17:04 +0200 (CEST)
Injection-Info dont-email.me; posting-host="041fd418ef8b485cdd75dbfc4b2fa6be"; logging-data="752477"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180A/F5dnt8je1qxe9ACZDqdbRtUier20E="
User-Agent Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock sha1:dFvwcV/qPGJ517LNriH1S3JOhW4= sha1:b6kja3CeqTwIrZ7q7rQc4raOoVo=
Xref csiph.com comp.lang.c:392119

Show key headers only | View raw


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.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

enums and switch vs function calls Richard Harnden <richard.nospam@gmail.invalid> - 2025-04-05 11:29 +0100
  Re: enums and switch vs function calls scott@slp53.sl.home (Scott Lurndal) - 2025-04-05 14:58 +0000
    Re: enums and switch vs function calls Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-04-06 03:17 -0700
      Re: enums and switch vs function calls scott@slp53.sl.home (Scott Lurndal) - 2025-04-06 14:47 +0000
        Re: enums and switch vs function calls David Brown <david.brown@hesbynett.no> - 2025-04-06 17:16 +0200
        Re: enums and switch vs function calls Tim Rentsch <tr.17687@z991.linuxsc.com> - 2025-04-06 19:26 -0700
  Re: enums and switch vs function calls David Brown <david.brown@hesbynett.no> - 2025-04-05 17:43 +0200
  Re: enums and switch vs function calls Thiago Adams <thiago.adams@gmail.com> - 2025-04-05 12:53 -0300
    Re: enums and switch vs function calls David Brown <david.brown@hesbynett.no> - 2025-04-06 11:49 +0200

csiph-web