#include #include #include #include #define VAR_TO_STR_BIN(x) \ obj_to_bin((char[sizeof(x) *CHAR_BIT + 1]){""}, &(x), sizeof(x)) char *obj_to_bin(char *dest, void *object, size_t osize) { const unsigned char *p = (const unsigned char *)object; p += osize; char *s = dest; while (osize-- > 0) { p--; unsigned i = CHAR_BIT; while (i-- > 0) { *s++ = ((*p >> i) & 1) + '0'; } } *s = '\0'; return dest; } struct t_aligned { char a __attribute__((aligned(16))); /* one byte plus 15 as padding here */ char b __attribute__((aligned(16))); }; struct t_unaligned { char a; char b; }; typedef struct t_aligned t_aligned; // Aligned typedef typedef struct t_unaligned t_unaligned; // Unaligned typedef int main(int argc, char **argv) { int a; int ptr_as_int; long int ptr_as_long; ptr_as_int = (int)&a; ptr_as_long = (long int)&a; printf("Sizeof pointer : %ld, PTR_AS_INT %x, PTR_AS_LONG_INT, %lx, %p", sizeof(&a), ptr_as_int, ptr_as_long, &a); t_aligned var_aligned; t_unaligned var_unaligned; printf("\n Aligned Start t : %p, t.a %p, t.b: %p, offset of t.a %ld, " "offset of t.b " "%ld", &var_aligned, &var_aligned.a, &var_aligned.b, offsetof(t_aligned, a), offsetof(t_aligned, b)); printf("\n Unaligned Start t : %p, t.a %p, t.b: %p, offset of t.a %ld, " "offset of t.b " "%ld", &var_unaligned, &var_unaligned.a, &var_unaligned.b, offsetof(t_unaligned, a), offsetof(t_unaligned, b)); }