TL; DR: Are 8-byte structures handled as efficiently as 8-byte uint64_t?
I have 3 data structures that are very similar. They are 6, 7 and 8 bytes long. I want to put them all in uint64_t variables. The goal is that comparisons and exercises will be very effective. (These values are used as a key for several (large) trees).
Example. I have defined the following data structure for which the length is 7 bytes.
typedef struct {
union {
uint64_t raw;
struct {
uint8_t unused;
uint8_t node_number;
uint8_t systemid[SYSTEMID_LENGTH];
} nodeid;
};
} nodeid_t;
Now I can perform quick assignments and copies through a raw union member.
nodeid_t x, y;
x.raw = y.raw
if (x.raw > y.raw) {
Etc etc.
My question is about using functions and assignments. When I pass this structure by value, whether the compiler (gcc) will recognize that these structures are 8 bytes long. And so treat as if they are int64_t?
: / :
int64_t my_function();
nodeid_t my_function();
, gcc 1 nodeid_t , ? 8 ? -O?
.
int64_t a, b;
nodeid_t x, y;
a = b;
x = y;