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

Joseph Myers josmyers@redhat.com
Tue Mar 11 21:56:45 GMT 2025


On Tue, 11 Mar 2025, Philip Prindeville wrote:

> > 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?

I don't have specific examples, but the fact the reasonably specified 
standard interfaces already exist is evidence against inventing something 
different.  (And glibc doesn't yet support encodefN / decodefN interfaces, 
but the implementation would more or less just be memcpy, since all 
supported configurations have the same endianness for integers and 
floating-point types.)

-- 
Joseph S. Myers
josmyers@redhat.com



More information about the Libc-alpha mailing list