Deutsch   English   Français   Italiano  
<wwvzfris2ox.fsf@LkoBDZeT.terraraq.uk>

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

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.gegeweb.eu!gegeweb.org!nntp.terraraq.uk!.POSTED.tunnel.sfere.anjou.terraraq.org.uk!not-for-mail
From: Richard Kettlewell <invalid@invalid.invalid>
Newsgroups: comp.lang.c
Subject: Re: Hex string literals (was Re: C23 thoughts and opinions)
Date: Tue, 18 Jun 2024 16:14:38 +0100
Organization: terraraq NNTP server
Message-ID: <wwvzfris2ox.fsf@LkoBDZeT.terraraq.uk>
References: <v2l828$18v7f$1@dont-email.me> <v2lji1$1bbcp$1@dont-email.me>
	<87msoh5uh6.fsf@nosuchdomain.example.com>
	<f08d2c9f-5c2e-495d-b0bd-3f71bd301432@gmail.com>
	<v2nbp4$1o9h6$1@dont-email.me> <v2ng4n$1p3o2$1@dont-email.me>
	<87y18047jk.fsf@nosuchdomain.example.com>
	<87msoe1xxo.fsf@nosuchdomain.example.com>
	<v2sh19$2rle2$2@dont-email.me>
	<87ikz11osy.fsf@nosuchdomain.example.com>
	<v2v59g$3cr0f$1@dont-email.me>
	<87plt8yxgn.fsf@nosuchdomain.example.com> <v31rj5$o20$1@dont-email.me>
	<87cyp6zsen.fsf@nosuchdomain.example.com>
	<v34gi3$j385$1@dont-email.me>
	<874jahznzt.fsf@nosuchdomain.example.com>
	<v36nf9$12bei$1@dont-email.me>
	<87v82b43h6.fsf@nosuchdomain.example.com>
	<87iky830v7.fsf_-_@nosuchdomain.example.com>
	<wwva5jj4zsw.fsf@LkoBDZeT.terraraq.uk>
	<878qz31096.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: innmantic.terraraq.uk; posting-host="tunnel.sfere.anjou.terraraq.org.uk:172.17.207.6";
	logging-data="35059"; mail-complaints-to="usenet@innmantic.terraraq.uk"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:dBCi/I1YfQSbP357R0VyUWRSr7g=
X-Face: h[Hh-7npe<<b4/eW[]sat,I3O`t8A`(ej.H!F4\8|;ih)`7{@:A~/j1}gTt4e7-n*F?.Rl^
     F<\{jehn7.KrO{!7=:(@J~]<.[{>v9!1<qZY,{EJxg6?Er4Y7Ng2\Ft>Z&W?r\c.!4DXH5PWpga"ha
     +r0NzP?vnz:e/knOY)PI-
X-Boydie: NO
Bytes: 3280
Lines: 36

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> Richard Kettlewell <invalid@invalid.invalid> writes:
>> There’s more to life than byte arrays, though, so I wonder if there’s
>> more to be said here. I find myself dealing a lot with large integers
>> generally represented as arrays of some unsigned type (commonly uint32_t
>> but other possibilities arise too).
>>
>> In C as it stands today this requires a translation step before
>> constants can be embedded in source code (which is error-prone if
>> someone attempts to do it manually).
>>
>> So being able to say ‘0x8732456872648956348596893765836543 as array of
>> uint64_t, LSW first’ (in some suitably C-like syntax) would be a big
>> improvement from my perspective, primarily as an accelerator to
>> development but also as a small improvement in robustness.
>
> You could use some kind of type punning.  For example, this is currently
> legal:
>
>     union {
>         unsigned char buf[4];
>         uint32_t n;
>     } obj = {
>         .buf = { 0x01, 0x02, 0x03, 0x04 }
>     };

I can’t use type punning if the data type is already set, which it often
is.

> The { 0x01, 0x02, 0x03, 0x04 } could be replaced with 0x"01020304".
>
> Of course you have to deal with endianness.

That’s a fatal problem for my use case.

-- 
https://www.greenend.org.uk/rjk/