Skip to content

Instantly share code, notes, and snippets.

@drj11
Created October 14, 2015 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drj11/da34a871aaa339b1c028 to your computer and use it in GitHub Desktop.
Save drj11/da34a871aaa339b1c028 to your computer and use it in GitHub Desktop.
Print sizes (in bits) of int, long, and pointer types in C
#include <assert.h>
#include <limits.h>
#include <stdio.h>
int main(void) {
size_t i = sizeof(int);
size_t l = sizeof(long);
size_t p = sizeof(void *);
assert(i <= INT_MAX/CHAR_BIT);
assert(l <= INT_MAX/CHAR_BIT);
assert(p <= INT_MAX/CHAR_BIT);
i *= CHAR_BIT;
l *= CHAR_BIT;
p *= CHAR_BIT;
printf("%d %d %d\n", (int)i, (int)l, (int)p);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment