Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #151889

Re: This statement may fall through - how?

Path csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: This statement may fall through - how?
Date Thu, 30 Apr 2020 15:19:17 -0700
Organization None to speak of
Lines 66
Message-ID <87d07o62hm.fsf@nosuchdomain.example.com> (permalink)
References <r8d5h9$qe1$1@dont-email.me> <hgukkrFpf1aU6@mid.individual.net> <87imhh7pk8.fsf@nosuchdomain.example.com> <r8fcfn$fmn$1@dont-email.me> <seErO5Tpfw5MbWWICM@bongo-ra.co>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
Injection-Info reader02.eternal-september.org; posting-host="3a8562cb4f6a88758e42aeb600e70f1e"; logging-data="12030"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jGBFz0oDrbnKrS9E8Uzp1"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)
Cancel-Lock sha1:4huUAwLpVwZgoXcPGae7cBRbicQ= sha1:VKaes38hL6d++1I5Djoo3T0zKdI=
Xref csiph.com comp.lang.c:151889

Show key headers only | View raw


Spiros Bousbouras <spibou@gmail.com> writes:
> On Thu, 30 Apr 2020 13:29:41 -0700
> mathog <mathog@caltech.edu> wrote:
[...]
> I assumed that the "C++11" Keith wrote was a typo and he meant "C11". If this
> really is about C++ then why are you asking here and not on  comp.lang.c++ ?

Yes, it was a typo (more precisely a thinko).  I meant C11.  (C++ has
had the [[noreturn]] attribute since C++11, but I wasn't referring
to that.)

I'll note, however, that the article that started this thread used a
command like:

    g++ [lots of options] fasta_formatter.cpp

It's likely that the same issues apply to C, but the OP probably should
have either posted to comp.lang.c++ or used a C example (which might be
as simple as changing the command and file name).  The rules for C and
C++ *might* be different, and the behavior of gcc and g++ could very
well be different.

>> That said while exit() may be Noreturn in certain language versions
>> 
>>    https://en.cppreference.com/w/cpp/utility/program/exit
>> 
>> how would shutting down the program result in a fall through to the next 
>> switch statement, which was the warning observed?

It wouldn't.  The question is whether the compiler (a) knows that and
(b) is required to know that.

The OP reported this error message:

fasta_formatter.cpp: In function ‘void parse_command_line(int, char**)’:
fasta_formatter.cpp:105:9: error: this statement may fall through
[-Werror=implicit-fallthrough=]
    usage();
    ~~~~~^~
fasta_formatter.cpp:107:3: note: here
   case 'i':
   ^~~~

Fallthough is not a constraint violation in C (nor does it violate
any rule in C++), so gcc or g++ would not normally treat it as a
fatal error.  It can do so with certain command-line options (such
as -Werror), but I didn't see any such options in the original post.
I can't easily reproduce the behavior, partly because the original
post did not provide a complete program (a number of #includes and
declarations were missing).

> As has been said , GCC does not know that the  exit()  in your code is the
> standard  exit() , it could be some other  exit()  which doesn't shut the
> programme down. Perhaps GCC could conclude that , taking also into account
> the command line options including those which get passed to the linker , but
> it wouldn't be worth the trouble since you can simply put  _Noreturn (I'm
> guessing GCC supported something like that before it became standard).

As has also been said, the compiler *can* assume that the exit
function being called is the standard exit function declared in
<stdlib.h>.  See C11/N1570 7.1.3.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

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


Thread

This statement may fall through - how? mathog <mathog@caltech.edu> - 2020-04-29 17:18 -0700
  Re: This statement may fall through - how? Ian Collins <ian-news@hotmail.com> - 2020-04-30 12:32 +1200
    Re: This statement may fall through - how? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-29 18:03 -0700
      Re: This statement may fall through - how? Ian Collins <ian-news@hotmail.com> - 2020-04-30 14:01 +1200
      Re: This statement may fall through - how? mathog <mathog@caltech.edu> - 2020-04-30 13:29 -0700
        Re: This statement may fall through - how? Spiros Bousbouras <spibou@gmail.com> - 2020-04-30 21:09 +0000
          Re: This statement may fall through - how? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-30 15:19 -0700
          Re: This statement may fall through - how? mathog <mathog@caltech.edu> - 2020-04-30 16:21 -0700
            Re: This statement may fall through - how? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-30 17:27 -0700
            Re: This statement may fall through - how? Ian Collins <ian-news@hotmail.com> - 2020-05-01 12:44 +1200
              Re: This statement may fall through - how? mathog <mathog@caltech.edu> - 2020-05-01 10:28 -0700
                Re: This statement may fall through - how? chad <cdalten@gmail.com> - 2020-05-01 12:43 -0700
  Re: This statement may fall through - how? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-29 17:58 -0700
  Re: This statement may fall through - how? scott@slp53.sl.home (Scott Lurndal) - 2020-04-30 01:25 +0000
    Re: This statement may fall through - how? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-29 18:37 -0700
  Re: This statement may fall through - how? Bonita Montero <Bonita.Montero@gmail.com> - 2020-04-30 10:33 +0200
    Re: This statement may fall through - how? gazelle@shell.xmission.com (Kenny McCormack) - 2020-04-30 08:48 +0000
      Re: This statement may fall through - how? Bonita Montero <Bonita.Montero@gmail.com> - 2020-04-30 10:54 +0200
        Re: This statement may fall through - how? James Harris <james.harris.1@gmail.com> - 2020-04-30 10:03 +0100
          Re: This statement may fall through - how? Bonita Montero <Bonita.Montero@gmail.com> - 2020-04-30 11:08 +0200
          Re: This statement may fall through - how? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-30 02:15 -0700
            Re: This statement may fall through - how? James Harris <james.harris.1@gmail.com> - 2020-04-30 12:27 +0100
              Re: This statement may fall through - how? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-04-30 13:42 +0100
              Re: This statement may fall through - how? James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-30 10:26 -0400
                Re: This statement may fall through - how? James Harris <james.harris.1@gmail.com> - 2020-04-30 17:43 +0100
                Re: This statement may fall through - how? James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-04-30 13:01 -0400
                Re: This statement may fall through - how? Spiros Bousbouras <spibou@gmail.com> - 2020-04-30 17:34 +0000
                Re: This statement may fall through - how? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2020-04-30 13:53 -0400
                Re: This statement may fall through - how? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-04-30 13:21 -0700
                Re: This statement may fall through - how? scott@slp53.sl.home (Scott Lurndal) - 2020-04-30 17:54 +0000
                Re: This statement may fall through - how? chad <cdalten@gmail.com> - 2020-04-30 10:55 -0700
              Re: This statement may fall through - how? Richard Damon <Richard@Damon-Family.org> - 2020-04-30 10:30 -0400
        Re: This statement may fall through - how? gazelle@shell.xmission.com (Kenny McCormack) - 2020-04-30 09:10 +0000
          Re: This statement may fall through - how? Bonita Montero <Bonita.Montero@gmail.com> - 2020-04-30 11:18 +0200
            Re: This statement may fall through - how? mathog <mathog@caltech.edu> - 2020-04-30 13:13 -0700

csiph-web