Article View: comp.lang.c
Article #348Re: Taming The Switch-Statement
From: Johann 'Myrkraverk' Oskarsson
Date: Tue, 13 Oct 2026 18:05
Date: Tue, 13 Oct 2026 18:05
35 lines
3361 bytes
3361 bytes
On 10/14/2026 1:28 AM, Stefan Ram wrote:
> Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> wrote or quoted:
>> signed main( void ){ switch( printf( "Hello!\n" ) ) break ; }
> . . .
>> Now GCC does /not/ complain about a useless break, unlike bart [1].
>> But isn't that a bug in GCC?
>
> With "-Wswitch-default", gcc will note that there is no "default".
>
> One can apply "clang-tidy" to that code to get,
>
> . . .
> |main.c:3:55: warning: 'break' will never be executed
> |signed main( void ){ switch( printf( "Hello!\n" ) ) break ; }
> | ^
> |main.c:3:55: warning: This statement is never executed
> |signed main( void ){ switch( printf( "Hello!\n" ) ) break ; }
> | ^
> |main.c:3:55: note: This statement is never executed
> |signed main( void ){ switch( printf( "Hello!\n" ) ) break ; }
> | ^
> . . .
>
> , but "clang-tidy" actually is intended for C++, so one will also
> get some warnings that do not apply to C programs.
Thank you. Now posters of comp.lang.c can indeed publish an issue of
the GCC magazine, and file a defect report on the behaviour of the com-
piler in the presence of a wild /break/ statement bound to an unlabelled
switch ().
--
Johann | email: invalid -> com | http://www.myrkraverk.com/blog/
I'm not from the Internet, I just work there. | via Easynews.com
https://bsky.app/profile/myrkraverk.bsky.social | for ( ;; ) _:;
Federated at https://fed.brid.gy/bsky/myrkraverk.bsky.social
Technical Details
Message-ID:
<cquzS.145357$koK3.143660@fx01.ams4>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!peer04.ams1!peer.ams1.xlned.com!news.xlned.com!fx01.ams4.POSTED!not-for-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <11ac0mi$19kfd$1@dont-email.me> <11ac2jv$1a84t$1@dont-email.me> <11ac783$1bkuo$1@kst.eternal-september.org> <11ad5eq$1l8hg$1@dont-email.me> <11aehqg$24k8m$3@kst.eternal-september.org> <11aenps$27sq7$1@dont-email.me> <11aetqv$29hmu$1@kst.eternal-september.org> <11afrfq$2j2o6$1@dont-email.me> <11agtkb$30q22$1@kst.eternal-september.org> <11ah16h$320sj$2@dont-email.me> <11ahqpu$38ir0$3@dont-email.me> <11aidi3$3gbu4$1@dont-email.me> <td6zS.60653$jNL6.31326@fx12.iad> <11aivdn$3nvmh$1@dont-email.me> <dI7zS.10223$AEj4.10181@fx17.ams4> <flag-20261012180101@ram.dialup.fu-berlin.de> <M7pzS.141305$wun8.135843@fx13.ams4> <tidy-20261013182719@ram.dialup.fu-berlin.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!peer04.ams1!peer.ams1.xlned.com!news.xlned.com!fx01.ams4.POSTED!not-for-mail MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Taming The Switch-Statement Newsgroups: comp.lang.c References: <119qf6l$2rmg3$1@dont-email.me> <11ac0mi$19kfd$1@dont-email.me> <11ac2jv$1a84t$1@dont-email.me> <11ac783$1bkuo$1@kst.eternal-september.org> <11ad5eq$1l8hg$1@dont-email.me> <11aehqg$24k8m$3@kst.eternal-september.org> <11aenps$27sq7$1@dont-email.me> <11aetqv$29hmu$1@kst.eternal-september.org> <11afrfq$2j2o6$1@dont-email.me> <11agtkb$30q22$1@kst.eternal-september.org> <11ah16h$320sj$2@dont-email.me> <11ahqpu$38ir0$3@dont-email.me> <11aidi3$3gbu4$1@dont-email.me> <td6zS.60653$jNL6.31326@fx12.iad> <11aivdn$3nvmh$1@dont-email.me> <dI7zS.10223$AEj4.10181@fx17.ams4> <flag-20261012180101@ram.dialup.fu-berlin.de> <M7pzS.141305$wun8.135843@fx13.ams4> <tidy-20261013182719@ram.dialup.fu-berlin.de> Content-Language: en-US From: Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> Organization: Watcom Pro Ltd. In-Reply-To: <tidy-20261013182719@ram.dialup.fu-berlin.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Lines: 35 Message-ID: <cquzS.145357$koK3.143660@fx01.ams4> X-Complaints-To: abuse@easynews.com X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly. Date: Wed, 14 Oct 2026 02:05:58 +0800 X-Received-Bytes: 3151