• Re: enums and switch vs function calls

    From Ben Bacarisse@3:633/280.2 to All on Fri Apr 25 10:12:22 2025
    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.

    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)
  • From Ben Bacarisse@3:633/280.2 to All on Fri Apr 25 10:12:43 2025
    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.

    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)
  • From Scott Lurndal@3:633/280.2 to All on Sat Apr 26 02:56:04 2025
    Reply-To: slp53@pacbell.net

    Ben Bacarisse <ben@bsb.me.uk> writes:
    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

    We use the latter. It doesn't get rid of the 'note' sections, however.

    For some reason, -fcompare-debug-second is commented out in our Makefile, but it appears that only applies in when a second compile is required.

    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: UsenetServer - www.usenetserver.com (3:633/280.2@fidonet)
  • From Ben Bacarisse@3:633/280.2 to All on Sat Apr 26 08:09:46 2025
    scott@slp53.sl.home (Scott Lurndal) writes:

    Ben Bacarisse <ben@bsb.me.uk> writes:
    scott@slp53.sl.home (Scott Lurndal) writes:

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
    ....
    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

    We use the latter. It doesn't get rid of the 'note' sections, however.

    For some reason, -fcompare-debug-second is commented out in our Makefile, but it appears that only applies in when a second compile is required.

    It appears to have a second "side-effect" use. It removes notes when I
    use it.

    --
    Ben.

    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)
  • From Tim Rentsch@3:633/280.2 to All on Sun May 4 23:55:53 2025
    Ben Bacarisse <ben@bsb.me.uk> writes:

    scott@slp53.sl.home (Scott Lurndal) writes:

    Ben Bacarisse <ben@bsb.me.uk> writes:

    scott@slp53.sl.home (Scott Lurndal) writes:

    Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

    ...

    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

    We use the latter. It doesn't get rid of the 'note' sections,
    however.

    For some reason, -fcompare-debug-second is commented out in our
    Makefile, but it appears that only applies in when a second compile
    is required.

    It appears to have a second "side-effect" use. It removes notes
    when I use it.

    Nice to know. Thank you for posting it.

    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)