Skip to content

Instantly share code, notes, and snippets.

Created April 15, 2016 05:27
What would you like to do?
Get offsets of struct members using offsetof
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct
int x;
short y[3];
long long z;
} data_t;
int main(int argc, char* argv[])
printf("x %d\n", offsetof(data_t, x));
printf("y %d\n", offsetof(data_t, y));
printf("y[1] %d\n", offsetof(data_t, y[1]));
printf("z %d\n", offsetof(data_t, z));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment