4 ms·
But C doesn't give you "exact control of memory layout". Bit-fields, structs, virtually everything except arrays has implementation-defined or unspecified memor
by Tomte 10y ago
But C doesn't give you "exact control of memory layout". Bit-fields, structs, virtually everything except arrays has implementation-defined or unspecified memory layout.
If you look at another old language, Ada, you'll find much more precise control.
- bluetomcat 10y agoC11 has `_Alignas(...)`, which works both with a size or a type. Before that, compiler-specific alignment attributes could be used, for example, GCC's `__attribute__((aligned(...)))`.
- rubber_duck 10y ago>implementation-defined In theory that's important, in practice you rely on implementation-defined behavior and put it behind a layer of macros. It's not perfect but it works - low level capabilities are not the problem in C. Lack of high level abstractions make scaling it up and maintaining a PITA.
- planteen 10y agoThat's true but at the end of the day it's fine as long as you aren't using those constructs for serialization/deserialization of data between machines. Rob Pike has a very good post about how Plan 9 needed no endian specific #defines: https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html?m=1 https://commandcenter.blogspot.com/2012/04/byte-order-fallac...