lundi 24 juin 2019

Packed structures and not packed without code repetition

I have this code:

// size probably 4 bytes
struct NotPacked
  {
  uint16_t first;
  uint8_t second;
  };

// size is 3 bytes
struct Packed
  {
  uint16_t first;
  uint8_t second;
  }__attribute__((packed));

I'd like to use the same structure, sometimes as packed, sometimes not. Do you know any way to write this code avoiding repetition?

Aucun commentaire:

Enregistrer un commentaire