Skip to content

Instantly share code, notes, and snippets.

@guyhughes
Last active April 13, 2016 23:55
Show Gist options
  • Save guyhughes/a368af9988b8426d703d166187a10f5e to your computer and use it in GitHub Desktop.
Save guyhughes/a368af9988b8426d703d166187a10f5e to your computer and use it in GitHub Desktop.
#include <bits/wordsize.h>
#include <stdio.h>
#include <inttypes.h>
int main(void)
{
uint64_t f, b, q, *foo, *bar, *qux;
foo=&f, bar=&b, qux=&q;
printf("size of a pointer is %d bytes\n",__WORDSIZE/8);
printf("size of an `int` is %d bytes\n",sizeof(f));
*qux = (uint64_t) foo;
*bar = (uint64_t) qux;
*foo = (uint64_t) bar;
printf("qux = %"PRIu64"\n",qux);
printf("foo = %"PRIu64"\n",foo);
printf("bar = %"PRIu64"\n",bar);
printf("\n");
printf("*qux = %"PRIu64"\n",*qux);
printf("*foo = %"PRIu64"\n",*foo);
printf("*bar = %"PRIu64"\n",*bar);
printf("\n");
printf("&qux = %"PRIu64"\n",&qux);
printf("&foo = %"PRIu64"\n",&foo);
printf("&bar = %"PRIu64"\n",&bar);
printf("\n");
printf("&qux == &foo → %d\n", &qux==&foo);
printf("*foo == &qux → %d\n" , (*foo == &qux) );
printf("*bar == *qux → %d\n" , (*bar == *qux) );
printf("\n");
return 0;
}
@guyhughes
Copy link
Author

please assume 64 bit arch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment