If you can afford to bind yourself to a single compiler (or do preprocessor hacks on compatibility issues), you can use the option of packed structures to get symbolic names for the values โโyou write. For example, in GCC:
struct __attribute__ ((__packed__)) packed_struct { char stuff_before[5] int some_value; } static char buffer2[256]; struct packed_struct *ps = buffer2; ps->some_value = valueToWrite;
This has several advantages:
- Your code more clearly reflects what you do if you name your fields well.
- Because the compiler knows if a platform that supports efficient, unequal access supports it, it can automatically choose between its own unrelated access or the corresponding workarounds on platforms that do not support unattached access.
But again, the main drawback is the lack of a standardized syntax.
source share