How to name unnamed fields in structure C?

Consider this structure:

struct {
    int a;
    int _reserved_000_[2];
    int b;
    int _reserved_001_[12];
    int c;    
};

Reserved fields should never be read or written. My structure is a handle to access the FPGA, where I got a lot of fields reserved. In the end, I called them a random name, because after a few years, the initial incremental numbering means nothing more.

So, I have a:

struct {
    int a;
    int _reserved_3hjdds1_[2];
    int b;
    int _reserved_40iuljk_[12];
    int c;    
};

It would be more convenient to have only empty fields:

struct {
    int a;
    int;
    int b;
    int;
    int c;    
};

But that will not work.

What other alternative can I avoid to avoid finding a unique name for the fields reserved?

+6
source share
1 answer

, :

#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;

, reserved11, reserved13, , , .

+3

Source: https://habr.com/ru/post/1015797/


All Articles