Created
October 14, 2015 08:23
-
-
Save drj11/da34a871aaa339b1c028 to your computer and use it in GitHub Desktop.
Print sizes (in bits) of int, long, and pointer types in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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