Skip to content

Instantly share code, notes, and snippets.

@antirez
Created May 18, 2016 16:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antirez/2b2c7d62606de5f2c3a35a5fde4811fb to your computer and use it in GitHub Desktop.
Save antirez/2b2c7d62606de5f2c3a35a5fde4811fb to your computer and use it in GitHub Desktop.
/tmp ➤ gcc foo.c -m32
/tmp ➤ ./a.out
one offset: 0
two offset: 4
three offset: 12
/tmp ➤ cat foo.c
#include <stdio.h>
#include <stdint.h>
struct foo {
int32_t one;
int64_t two;
int32_t three;
};
int main(void) {
struct foo f;
printf("one offset: %lu\n",(unsigned long)&f.one - (unsigned long)&f);
printf("two offset: %lu\n",(unsigned long)&f.two - (unsigned long)&f);
printf("three offset: %lu\n",(unsigned long)&f.three - (unsigned long)&f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment