Oddbean new post about | logout
 @ec6e9c30, could thou elaborate on the task?  As in a homogeneous buffer with dynamic length or a packed struct? 
 @edec528e I mean there must be a better way than this right?

https://cdn.fosstodon.org/media_attachments/files/111/132/017/654/098/209/original/e880b7fa89ad6885.png 
 Hmmm @ec6e9c30, doesn’t seem to be POSIX, but most libc seem to provide bswap(3) which I’d use optionally #if the target is big endian, then cast to the target struct.

I don’t think there’s a better way at machine level, e.g. in Zig with comptime and @byteSwap builtin it would look less like a hack but 🤷 
 @edec528e I at least don't have to are about the endianness of the platform, it's all network-endian and it's building for arm microcontrollers. Nothing posix in this stack :P 
 @ec6e9c30 @edec528e Not really, this is portable to any endianness. Check Rob Pike article on this: https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html