Skip to content

Instantly share code, notes, and snippets.

@cprieto
Created November 21, 2018 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cprieto/a1be4ad7844c28cf0c4d98bdea60989f to your computer and use it in GitHub Desktop.
Save cprieto/a1be4ad7844c28cf0c4d98bdea60989f to your computer and use it in GitHub Desktop.
#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