Created
December 11, 2023 17:53
-
-
Save mlabbe/074109231031839b21f0c7ae80749e36 to your computer and use it in GitHub Desktop.
C Print sizeof all 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
#include <stdio.h> | |
#include <stdint.h> // uintptr_t | |
#include <stddef.h> // size_t | |
// enable printing sizes as ints to avoid faliing on compilers that don't support %zu | |
#define SIZEOF(expr) (int)sizeof(expr) | |
#define PRINT_SIZEOF(expr) printf("sizeof(%-11s) = %1d\n", #expr, SIZEOF(expr)) | |
int main(void) { | |
PRINT_SIZEOF(char); | |
PRINT_SIZEOF(short); | |
PRINT_SIZEOF(int); | |
PRINT_SIZEOF(long); | |
PRINT_SIZEOF(long long); | |
PRINT_SIZEOF(float); | |
PRINT_SIZEOF(double); | |
PRINT_SIZEOF(long double); | |
PRINT_SIZEOF(uintptr_t); | |
PRINT_SIZEOF(size_t); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results from my systems: