bluemoon wrote:Love4Boobies wrote:Of course. My code does proper serialization and can be compiled with any C compiler..
May I know how you do it, for example, on ethernet packet structure? I'd be grad to learn more methods.
There's no one true way to achieve serialization---it depends on what it is you are doing. Two techniques that I find useful are to use arrays, and files (which are particularly useful in debugging); again, not everything is suitable in every scenario.
bluemoon wrote:A greb on FreeBSD and Linux source I found even they used (packed), and they seems not worry much on not conforming this standard.
I don't know about FreeBSD but Linux is indeed tied to GCC.
bluemoon wrote:By the way, when dealing with OS dev, IMO we sometime need to push to the edge on standards in trade of convenience; provided that the ugly code is controllable size.
If you need to write ugly code then you're either using your tools the wrong way or you're not using the right tools for the job.
bluemoon wrote:Another example would be data alignment and the know fact that on x86, some operations are atomic on aligned data;
C as a HLL would never define any atomic operation and it may not even work on other architecture, but sometime you still got some architecture dependent code for some reasons.
It's true that there are very few atomic things in C (e.g., sig_atomic_t) but the upcoming standard, currently dubbed C1X, adds full atomicity support via the _Atomic type and <stdatomic.h> in order to fix this issue. As for architecture-dependent code, it is indeed important for OS developers (and others)---this is one of the reasons for which the standard defines unspecified behavior, undefined behavior, implementation-defined behavior, and locale-specific behavior. Many other languages have similar concepts.
In traditional C, C89, and C99, alignment (which is unrelated to atomicity) can be forced via unions and bit-fields. However, C1X brings alignment closer to the programmer as well: aligned_alloc, _Alignas, alignof, and <stdalign.h>.