Skip to content

Instantly share code, notes, and snippets.

@yoggy
Last active August 29, 2015 13:56
Show Gist options
  • Save yoggy/8930006 to your computer and use it in GitHub Desktop.
Save yoggy/8930006 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stddef.h>
typedef struct _hoge {
int a;
char c;
float f;
} Hoge;
int main(int argc, char* argv[])
{
printf(
"%d %d\n",
offsetof(Hoge, f),
&(((Hoge*)NULL)->f)
);
return 0;
}
$ gcc offsetof-test.c
$ ./a.out
8 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment