-
-
Save shelllee/80a2cdea2a69cdd4ea31b6c25bb779d8 to your computer and use it in GitHub Desktop.
[C][emscripten]sizeof number types
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
// clang -Wall -Wextra -std=c11 sizeof.c -o sizeof | |
// emcc -Wall -Wextra -std=c11 sizeof.c -o sizeof.js | |
#include <stdlib.h> | |
#include <stdarg.h> | |
#include <stddef.h> | |
#include <stdio.h> | |
#include <wchar.h> | |
#include <time.h> | |
#include <setjmp.h> | |
#include <locale.h> | |
// C99 | |
#include <stdbool.h> | |
#include <inttypes.h> | |
#include <complex.h> | |
#include <fenv.h> | |
// C11 | |
#include <stdalign.h> | |
//#include <threads.h> | |
#define show_size(type) printf(\ | |
"sizeof (" #type ") = %zu, alignof (" #type ") == %zu\n", \ | |
sizeof (type), alignof(type)) | |
int main(int argc, char* argv[]) | |
{ | |
(void) argc, (void) argv; | |
// basic number type | |
show_size(char); | |
show_size(short); | |
show_size(int); | |
show_size(long); | |
show_size(long long); | |
show_size(float); | |
show_size(double); | |
show_size(long double); | |
// other num types | |
show_size(size_t); | |
show_size(ptrdiff_t); | |
show_size(wchar_t); | |
show_size(wint_t); | |
// libc types | |
show_size(div_t); | |
//show_size(FILE); // only "typedef struct _IO_FILE FILE;" in emscripten libc | |
show_size(fpos_t); | |
show_size(time_t); | |
show_size(clock_t); | |
show_size(struct tm); | |
show_size(va_list); | |
show_size(mbstate_t); | |
show_size(jmp_buf); | |
show_size(struct lconv); | |
// C99 types | |
show_size(bool); | |
show_size(intmax_t); | |
show_size(uintptr_t); | |
show_size(float complex); | |
show_size(double complex); | |
show_size(long double complex); | |
show_size(fenv_t); | |
show_size(fexcept_t); | |
return 0; | |
} |
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
$ emcc -Wall -Wextra -std=c11 sizeof.c -o sizeof.js | |
$ iojs sizeof.js | |
sizeof (char) = 1, alignof (char) == 1 | |
sizeof (short) = 2, alignof (short) == 2 | |
sizeof (int) = 4, alignof (int) == 4 | |
sizeof (long) = 4, alignof (long) == 4 | |
sizeof (long long) = 8, alignof (long long) == 8 | |
sizeof (float) = 4, alignof (float) == 4 | |
sizeof (double) = 8, alignof (double) == 8 | |
sizeof (long double) = 8, alignof (long double) == 8 | |
sizeof (size_t) = 4, alignof (size_t) == 4 | |
sizeof (ptrdiff_t) = 4, alignof (ptrdiff_t) == 4 | |
sizeof (wchar_t) = 4, alignof (wchar_t) == 4 | |
sizeof (wint_t) = 4, alignof (wint_t) == 4 | |
sizeof (div_t) = 8, alignof (div_t) == 4 | |
sizeof (fpos_t) = 16, alignof (fpos_t) == 8 | |
sizeof (time_t) = 4, alignof (time_t) == 4 | |
sizeof (clock_t) = 4, alignof (clock_t) == 4 | |
sizeof (struct tm) = 44, alignof (struct tm) == 4 | |
sizeof (va_list) = 16, alignof (va_list) == 4 | |
sizeof (mbstate_t) = 8, alignof (mbstate_t) == 4 | |
sizeof (jmp_buf) = 156, alignof (jmp_buf) == 4 | |
sizeof (struct lconv) = 56, alignof (struct lconv) == 4 | |
sizeof (bool) = 1, alignof (bool) == 1 | |
sizeof (intmax_t) = 8, alignof (intmax_t) == 8 | |
sizeof (uintptr_t) = 4, alignof (uintptr_t) == 4 | |
sizeof (float complex) = 8, alignof (float complex) == 4 | |
sizeof (double complex) = 16, alignof (double complex) == 8 | |
sizeof (long double complex) = 16, alignof (long double complex) == 8 | |
sizeof (fenv_t) = 32, alignof (fenv_t) == 4 | |
sizeof (fexcept_t) = 2, alignof (fexcept_t) == 2 | |
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
$ clang -Wall -Wextra -std=c11 sizeof.c -o sizeof | |
$ ./sizeof | |
sizeof (char) = 1, alignof (char) == 1 | |
sizeof (short) = 2, alignof (short) == 2 | |
sizeof (int) = 4, alignof (int) == 4 | |
sizeof (long) = 8, alignof (long) == 8 | |
sizeof (long long) = 8, alignof (long long) == 8 | |
sizeof (float) = 4, alignof (float) == 4 | |
sizeof (double) = 8, alignof (double) == 8 | |
sizeof (long double) = 16, alignof (long double) == 16 | |
sizeof (size_t) = 8, alignof (size_t) == 8 | |
sizeof (ptrdiff_t) = 8, alignof (ptrdiff_t) == 8 | |
sizeof (wchar_t) = 4, alignof (wchar_t) == 4 | |
sizeof (wint_t) = 4, alignof (wint_t) == 4 | |
sizeof (div_t) = 8, alignof (div_t) == 4 | |
sizeof (fpos_t) = 8, alignof (fpos_t) == 8 | |
sizeof (time_t) = 8, alignof (time_t) == 8 | |
sizeof (clock_t) = 8, alignof (clock_t) == 8 | |
sizeof (struct tm) = 56, alignof (struct tm) == 8 | |
sizeof (va_list) = 24, alignof (va_list) == 8 | |
sizeof (mbstate_t) = 128, alignof (mbstate_t) == 8 | |
sizeof (jmp_buf) = 148, alignof (jmp_buf) == 4 | |
sizeof (struct lconv) = 96, alignof (struct lconv) == 8 | |
sizeof (bool) = 1, alignof (bool) == 1 | |
sizeof (intmax_t) = 8, alignof (intmax_t) == 8 | |
sizeof (uintptr_t) = 8, alignof (uintptr_t) == 8 | |
sizeof (float complex) = 8, alignof (float complex) == 4 | |
sizeof (double complex) = 16, alignof (double complex) == 8 | |
sizeof (long double complex) = 32, alignof (long double complex) == 16 | |
sizeof (fenv_t) = 16, alignof (fenv_t) == 4 | |
sizeof (fexcept_t) = 2, alignof (fexcept_t) == 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment