Created
November 21, 2018 08:35
-
-
Save cprieto/a1be4ad7844c28cf0c4d98bdea60989f to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
#include <stdlib.h> | |
#include <stdbool.h> | |
#include <stddef.h> | |
typedef int *ptr_int; | |
typedef struct unordered { | |
int a; | |
double b; | |
bool c; | |
} Unordered; | |
typedef struct ordered_ { | |
bool c; | |
int a; | |
double b; | |
} Ordered; | |
int main() { | |
printf("int: %lu\n", sizeof(int)); | |
printf("long: %lu\n", sizeof(long int)); | |
printf("float: %lu\n", sizeof(float)); | |
printf("double: %lu\n", sizeof(double)); | |
printf("word: %lu\n", sizeof(ptr_int)); | |
printf("---\n"); | |
printf("Unordered: %lu\n", sizeof(Unordered)); | |
printf("Offset a: %lu\n", offsetof(Unordered, a)); | |
printf("Offset b: %lu\n", offsetof(Unordered, b)); | |
printf("Offset c: %lu\n", offsetof(Unordered, c)); | |
printf("---\n"); | |
printf("Ordered: %lu\n", sizeof(Ordered)); | |
printf("Offset c: %lu\n", offsetof(Ordered, c)); | |
printf("Offset a: %lu\n", offsetof(Ordered, a)); | |
printf("Offset b: %lu\n", offsetof(Ordered, b)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment