Created
October 25, 2017 22:59
-
-
Save jonasraoni/513f655d528ec5430d708ce4683eb381 to your computer and use it in GitHub Desktop.
Displays the memory alignment of each data type.
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> | |
#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