Let's consider this structure:
struct {
int a;
int _reserved_000_[2];
int b;
int _reserved_001_[12];
int c;
};
The reserved fields should never be read or written. My structure represents a descriptor to address an FPGA where I got a lot of reserved
fields. I eventually named them with random named because after years the initial ascending numbering doesn't mean anything anymore.
So I have now:
struct {
int a;
int _reserved_3hjdds1_[2];
int b;
int _reserved_40iuljk_[12];
int c;
};
It would be more convenient to have just empty fields instead:
struct {
int a;
int;
int b;
int;
int c;
};
But it doesn't work.
What other alternative can I just that avoid finding unique name for reserved
fields?
It should be possible to achieve what you want with a bit of macro-magic:
#include <stdint.h>
#define CONCAT(x, y) x ## y
#define EXPAND(x, y) CONCAT(x, y)
#define RESERVED EXPAND(reserved, __LINE__)
struct
{
uint32_t x;
uint32_t RESERVED;
uint16_t y;
uint64_t RESERVED[10];
} s;
This gives you identifiers such as reserved11
, reserved13
, but the names obviously don't matter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With