Skip to content

Instantly share code, notes, and snippets.

@jonasraoni
Created Oct 25, 2017
Embed
What would you like to do?
Displays the memory alignment of each data type.
#include <stdio.h>
#define ALIGN_OF(t) ((int)(sizeof(struct{char c; t x;}) - sizeof(t)))
int main()
{
printf("char: %d\n", ALIGN_OF(char));
printf("short: %d\n", ALIGN_OF(short));
printf("int: %d\n", ALIGN_OF(int));
printf("long: %d\n", ALIGN_OF(long));
printf("long long: %d\n", ALIGN_OF(long long));
printf("void*: %d\n", ALIGN_OF(void*));
printf("float: %d\n", ALIGN_OF(float));
printf("double: %d\n", ALIGN_OF(double));
printf("long double: %d\n", ALIGN_OF(long double));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment