Skip to content

Instantly share code, notes, and snippets.

@daniel-packard
Last active March 18, 2016 19:52
Show Gist options
  • Save daniel-packard/b1078384d42f733d1ea2 to your computer and use it in GitHub Desktop.
Save daniel-packard/b1078384d42f733d1ea2 to your computer and use it in GitHub Desktop.
Demo on how to provide a padded wrapper for a struct to ensure it takes up 64Bytes, even as members are added/removed
#include <stdio.h>
typedef struct {
int a;
int b;
char c;
} unpadded_t;
typedef struct {
unpadded_t data;
char padding[64-sizeof(unpadded_t)];
} padded_t;
int main(int argc, char* argv[]) {
printf("size of unpadded: %lu\n",sizeof(unpadded_t));
printf("size of padded: %lu\n",sizeof(padded_t));
padded_t packet = { .data = { .a=1, .b=2, .c='C' } };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment