Last active
March 18, 2016 19:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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