[PATCH v2 1/1] inet: add support for 64-bit network byte order

Philip Prindeville philipp_subx@redfish-solutions.com
Tue Mar 11 21:29:42 GMT 2025



> On Mar 11, 2025, at 1:00 PM, Joseph Myers <josmyers@redhat.com> wrote:
> 
> On Tue, 11 Mar 2025, Philip Prindeville wrote:
> 
>> Y’all know where I was going to go with this next, right?
>> 
>> Yup, standardized marshaling for float and double…
> 
> You can use printf with %a to output those as hex float strings.
> 
> Alternatively, C23 Annex H defines encodefN / decodefN functions that can 
> be used with _Float32 / _Float64 (and that follow __STDC_ENDIAN_NATIVE__, 
> so you'd then need to do endian conversion; endian-aware loads / stores 
> didn't get into the C standard before C2Y, but you could of course combine 
> encodefN / decodefN with interfaces such as htobe64; encodefN / decodefN 
> use unsigned char arrays, so you can cast a pointer to an integer and the 
> aliasing is OK).  Since _Float32 and _Float64 are defined to follow the 
> semantics of IEEE interchange formats, they are semantically preferable to 
> float and double for this - just as uint64_t is preferable to unsigned 
> long long for such purposes (both in the types used in the interfaces, and 
> in the naming where "64" is preferable to "ll").
> 
> -- 
> Joseph S. Myers
> josmyers@redhat.com



Got any example of code that does this that I could study?

Thanks



More information about the Libc-alpha mailing list