Article View: comp.lang.c
Article #7Re: Taming The Switch-Statement
From: Andrey Tarasevich
Date: Wed, 07 Oct 2026 03:36
Date: Wed, 07 Oct 2026 03:36
67 lines
3062 bytes
3062 bytes
On Sat 10/3/2026 9:36 AM, bart wrote:
> On 03/10/2026 17:02, David Brown wrote:
>> On 03/10/2026 10:43, Lawrence D’Oliveiro wrote:
>>> How not to forget to end each case-sequence in a switch statement with
>>> a break-statement: put the break at the same indentation level as the
>>> case-clause as well as the switch-expression. That way, you can scan
>>> your eye down a single line for each switch-statement to be sure that
>>> no breaks are missing. A reasonably-complex example, with a nested
>>> switch for added interest:
>>>
>>
>> gcc -Werror=implict-fallthrough
>
>
> I assume this is for non-empty blocks? Otherwise this will be an error:
>
> case 'A': case 'B': case 'C':
> // deal with ABC
This is not, but in other cases there are still some differences between
implementations.
For example, Clang approaches this matter rather formally. This:
switch (0)
{
case 0:;
case 1:;
case 2:;
}
is already sufficient to trigger fallthrough warnings in Clang under
`-Wimplicit-fallthrough`, even tough all "blocks" in the above are empty
for all practical means and purposes.
GCC will remain silent for the above code. This will keep it silent as well:
switch (0)
{
case 0:;
case 1:;
case 2: printf("World");
}
This produces no warnings either:
switch (0)
{
case 0: printf("Hello ");
case 1:;
case 2:;
}
And finally this:
switch (0)
{
case 0: printf("Hello ");
case 1:;
case 2: printf("World");
}
will trigger a warning under `-Wimplicit-fallthrough`. So, GCC appears
to look for a fallthrough from a non-empty to a non-empty before it warns.
--
Best regards,
Andrey
Technical Details
Message-ID:
<11a4enp$2h5ld$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<119qf6l$2rmg3$1@dont-email.me> <119r8u3$34nce$1@dont-email.me> <119rau4$35ugq$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Andrey Tarasevich <noone@noone.net> Newsgroups: comp.lang.c Subject: Re: Taming The Switch-Statement Date: Tue, 6 Oct 2026 20:36:23 -0700 Organization: A noiseless patient Spider Lines: 67 Message-ID: <11a4enp$2h5ld$1@dont-email.me> References: <119qf6l$2rmg3$1@dont-email.me> <119r8u3$34nce$1@dont-email.me> <119rau4$35ugq$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 07 Oct 2026 03:36:28 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2660013"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185XFhiImYE9CWftTTKv8sF"; posting-host="ce994793327b623058c29271269c1ad9" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:f2N633WLIuxNzkcoqcaWKUDkB3w= sha256:pa1Gcu4iy309roGrZwV8U9k8YvWQ6ttKBXBeWYK3r/0= sha1:IGYRLwqxoAuAGzXQCqcIDWTqcUQ= sha256:7zjwEwDiLLtAs8DFfitXg55XrkvVKAuY39vBTBaShgQ= Content-Language: en-US In-Reply-To: <119rau4$35ugq$1@dont-email.me>