Skip to content

Instantly share code, notes, and snippets.

@vobject
Created October 3, 2012 05:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vobject/3825201 to your computer and use it in GitHub Desktop.
Save vobject/3825201 to your computer and use it in GitHub Desktop.
Sizes of C data types
/*
* gcc -std=c99 -pedantic -Wall sizeof.c && ./a.out
* clang -std=c99 -pedantic -Wall sizeof.c && ./a.out
*/
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include <sys/time.h>
int main(void)
{
printf("size_t: %zu\n", sizeof(size_t));
printf("bool: %zu\n", sizeof(bool));
printf("char: %zu\n", sizeof(char));
printf("short: %zu\n", sizeof(short));
printf("int: %zu\n", sizeof(int));
printf("long: %zu\n", sizeof(long));
printf("long long: %zu\n", sizeof(long long));
printf("float: %zu\n", sizeof(float));
printf("double: %zu\n", sizeof(double));
printf("long double: %zu\n", sizeof(long double));
printf("clock_t: %zu\n", sizeof(clock_t));
printf("time_t: %zu\n", sizeof(time_t));
printf("struct tm: %zu\n", sizeof(struct tm));
printf("struct timeval: %zu\n", sizeof(struct timeval));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment