Deutsch   English   Français   Italiano  
<vso9fa$34vau$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Muttley@DastardlyHQ.org
Newsgroups: comp.lang.c
Subject: Re: "A diagram of C23 basic types"
Date: Fri, 4 Apr 2025 09:40:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <vso9fa$34vau$1@dont-email.me>
References: <87y0wjaysg.fsf@gmail.com> <vsj1m8$1f8h2$1@dont-email.me>
 <vsj2l9$1j0as$1@dont-email.me> <vsjef3$1u4nk$1@dont-email.me>
 <vsjg6t$20pdb$1@dont-email.me> <vsjjd1$23ukt$1@dont-email.me>
 <vsjkvb$25mtg$1@dont-email.me> <vpdHP.1828825$TBhc.94105@fx16.iad>
 <vslhrm$7uv3$1@dont-email.me> <vsll4b$8mfb$3@dont-email.me>
 <vslq6b$ginf$1@dont-email.me>
 <vsm45d$ncfh$4@dont-email.me>
Injection-Date: Fri, 04 Apr 2025 11:40:58 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c4d4e4980b3de0ab40f443eec29dc220";
	logging-data="3308894"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/tkjPGvMs/CX5WzIt55F5f"
Cancel-Lock: sha1:F+f7hMKS+dt6ItEZmtNwURnYjfM=
Bytes: 2932

On Thu, 3 Apr 2025 15:58:05 +0200
David Brown <david.brown@hesbynett.no> wibbled:
>Human readers prefer clear code to comments.  Comments get out of sync - 
>code does not.

Thats not a reason for not using comments. Its very easy to understand your
own code that you've just written - not so much for someone else or for you
years down the line.

>Ignorance is curable - wilful ignorance is much more stubborn.  But I 
>will try.

Guffaw! You should do standup.

>Let me give you an example, paraphrased from the C23 standards:
>
>
>	#include <stddef.h>
>
>	enum Colours { red, green, blue };
>
>	unsigned int colour_to_hex(enum Colours c) {
>	    switch (c) {
>	        case red : return 0xff'00'00;
>	        case green : return 0x00'ff'00;
>	        case blue : return 0x00'00'ff;
>	    }
>	    unreachable();
>	}
>
>
>With "unreachable()", "gcc -std=c23 -O2 -Wall" gives :
>
>	colour_to_hex:
>         	mov     edi, edi
>	        mov     eax, DWORD PTR CSWTCH.1[0+rdi*4]
>	        ret
>
>Without it, it gives :
>
>	colour_to_hex:
>         	cmp     edi, 2
>	        ja      .L1
>	        mov     edi, edi
>         	mov     eax, DWORD PTR CSWTCH.1[0+rdi*4]
>	.L1:
>	        ret

Except its not unreachable is it? There's nothing in C to prevent you
calling that function with a value other than defined in the enum so what
happens if there's a bug and it hits unreachable? Oh thats right , its
"undefined" ie , a crash or hidden bug with bugger all info.

>Neither "// This should never be reached" nor "assert(false);" is a 
>suitable alternative.

In your opinion. I would never use that example above, its just asking for
trouble down the line.

Also FWIW, putting seperators in the hex values makes it less readable to me
not more.