Skip to content

Instantly share code, notes, and snippets.

@jeremy-code
Created April 27, 2025 04:54
Show Gist options
  • Save jeremy-code/85384d5ee0df4bbddd5cd5de1daf373e to your computer and use it in GitHub Desktop.
Save jeremy-code/85384d5ee0df4bbddd5cd5de1daf373e to your computer and use it in GitHub Desktop.
Emscripten sizeof types in bytes C WASM64
// main.c

#include <emscripten.h>

int EMSCRIPTEN_KEEPALIVE main() {
    printf("sizeof(bool): %zu\n", sizeof(bool));
    printf("sizeof(char): %zu\n", sizeof(char));
    printf("sizeof(signed char): %zu\n", sizeof(signed char));
    printf("sizeof(unsigned char): %zu\n", sizeof(unsigned char));
    printf("sizeof(short): %zu\n", sizeof(short));
    printf("sizeof(short int): %zu\n", sizeof(short int));
    printf("sizeof(signed short): %zu\n", sizeof(signed short));
    printf("sizeof(signed short int): %zu\n", sizeof(signed short int));
    printf("sizeof(unsigned short): %zu\n", sizeof(unsigned short));
    printf("sizeof(unsigned short int): %zu\n", sizeof(unsigned short int));
    printf("sizeof(int): %zu\n", sizeof(int));
    printf("sizeof(signed): %zu\n", sizeof(signed));
    printf("sizeof(signed int): %zu\n", sizeof(signed int));
    printf("sizeof(unsigned): %zu\n", sizeof(unsigned));
    printf("sizeof(unsigned int): %zu\n", sizeof(unsigned int));
    printf("sizeof(long): %zu\n", sizeof(long));
    printf("sizeof(long int): %zu\n", sizeof(long int));
    printf("sizeof(signed long): %zu\n", sizeof(signed long));
    printf("sizeof(signed long int): %zu\n", sizeof(signed long int));
    printf("sizeof(unsigned long): %zu\n", sizeof(unsigned long));
    printf("sizeof(unsigned long int): %zu\n", sizeof(unsigned long int));
    printf("sizeof(long long): %zu\n", sizeof(long long));
    printf("sizeof(long long int): %zu\n", sizeof(long long int));
    printf("sizeof(signed long long): %zu\n", sizeof(signed long long));
    printf("sizeof(signed long long int): %zu\n", sizeof(signed long long int));
    printf("sizeof(unsigned long long): %zu\n", sizeof(unsigned long long));
    printf("sizeof(unsigned long long int): %zu\n", sizeof(unsigned long long int));
    printf("sizeof(float): %zu\n", sizeof(float));
    printf("sizeof(double): %zu\n", sizeof(double));
    printf("sizeof(long double): %zu\n", sizeof(long double));

    return 0;
}
❯ node index.js
sizeof(bool): 1
sizeof(bool): 1
sizeof(char): 1
sizeof(signed char): 1
sizeof(unsigned char): 1
sizeof(short): 2
sizeof(short int): 2
sizeof(signed short): 2
sizeof(signed short int): 2
sizeof(unsigned short): 2
sizeof(unsigned short int): 2
sizeof(int): 4
sizeof(signed): 4
sizeof(signed int): 4
sizeof(unsigned): 4
sizeof(unsigned int): 4
sizeof(long): 4
sizeof(long int): 4
sizeof(signed long): 4
sizeof(signed long int): 4
sizeof(unsigned long): 4
sizeof(unsigned long int): 4
sizeof(long long): 8
sizeof(long long int): 8
sizeof(signed long long): 8
sizeof(signed long long int): 8
sizeof(unsigned long long): 8
sizeof(unsigned long long int): 8
sizeof(float): 4
sizeof(double): 8
sizeof(long double): 16

I then tried it out with -sMEMORY64=1 and got the same output. The only change I noticed was that pointers went from 4 bytes to 8 bytes.

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