Sujet : Re: Hex string literals (was Re: C23 thoughts and opinions)
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.cDate : 18. Jun 2024, 16:20:12
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4s8jc$1d30n$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 18/06/2024 11:39, Michael S wrote:
On Mon, 17 Jun 2024 22:39:00 -0700
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
bart <bc@freeuk.com> writes:
>
AFAIK nobody uses octal anymore.
>
There are circumstances where being able to write constants
in octal is useful. It also would be nice to be able to
write constants in base 4 and base 32 (because 5 is half
of 10). I don't have occasion to prefer octal very often
but I'm glad it's there for those times when I do.
Ada/VHDL permits any base from 2 to 16. They didn't go as far up as
32.
I would imagine that reading base 32 number would take time to become
accustomed.
I can't imagine any possible use for such bases. Base 16 is very common, and base 2 is useful in some circumstances. Base 8 has, to my knowledge, a single non-archaic use-case and that is for chmod modes in *nix programming.
I think support for other bases exists in some languages as a side-effect of wanting an explicit numbered base notation for bases 2, 16 and possibly 8, rather than using 0b, 0x and 0o (or 0q, or just 0 as an April fool's joke).
If I were the BDFL of C, I'd remove octal constants and add a macro "_Octal" with definition:
#define _Octal(n) (((n) % 10) + ((n) / 10 % 10) * 8 \
+ ((n) / 100 % 10) * 64 + ((n) / 1000 % 10) * 512)
If anyone can present a good use for base 4 or base 32, I might change my mind :-)