Skip to content

Instantly share code, notes, and snippets.

@Costava
Created February 19, 2021 06:29
Show Gist options
  • Save Costava/bfdc8acc2391db3a776382de41f818f1 to your computer and use it in GitHub Desktop.
Save Costava/bfdc8acc2391db3a776382de41f818f1 to your computer and use it in GitHub Desktop.
Print the size of many types.
// Example compilation:
// gcc typesizes.c -o typesizes -std=c99 -Wall
// Info on integer types: https://en.cppreference.com/w/c/types/integer
#include <stdint.h>
#include <stdio.h>
int main(void) {
printf("sizeof(int): %ld\n", sizeof(int));
printf("sizeof(unsigned int): %ld\n", sizeof(unsigned int));
printf("sizeof(short int): %ld\n", sizeof(short int));
printf("sizeof(long int): %ld\n", sizeof(long int));
printf("sizeof(char): %ld\n", sizeof(char));
printf("sizeof(void*): %ld\n", sizeof(void*));
printf("sizeof(intmax_t): %ld\n", sizeof(intmax_t));
printf("sizeof(uintmax_t): %ld\n", sizeof(uintmax_t));
printf("sizeof(intptr_t): %ld\n", sizeof(intptr_t));
printf("sizeof(uintptr_t): %ld\n", sizeof(uintptr_t));
puts("");
printf("sizeof(int_fast8_t): %ld\n", sizeof(int_fast8_t));
printf("sizeof(int_fast16_t): %ld\n", sizeof(int_fast16_t));
printf("sizeof(int_fast32_t): %ld\n", sizeof(int_fast32_t));
printf("sizeof(int_fast64_t): %ld\n", sizeof(int_fast64_t));
puts("");
printf("sizeof(uint_fast8_t): %ld\n", sizeof(uint_fast8_t));
printf("sizeof(uint_fast16_t): %ld\n", sizeof(uint_fast16_t));
printf("sizeof(uint_fast32_t): %ld\n", sizeof(uint_fast32_t));
printf("sizeof(uint_fast64_t): %ld\n", sizeof(uint_fast64_t));
puts("");
printf("sizeof(int_least8_t): %ld\n", sizeof(int_least8_t));
printf("sizeof(int_least16_t): %ld\n", sizeof(int_least16_t));
printf("sizeof(int_least32_t): %ld\n", sizeof(int_least32_t));
printf("sizeof(int_least64_t): %ld\n", sizeof(int_least64_t));
puts("");
printf("sizeof(uint_least8_t): %ld\n", sizeof(uint_least8_t));
printf("sizeof(uint_least16_t): %ld\n", sizeof(uint_least16_t));
printf("sizeof(uint_least32_t): %ld\n", sizeof(uint_least32_t));
printf("sizeof(uint_least64_t): %ld\n", sizeof(uint_least64_t));
return 0;
}
/* BSD Zero Clause License
Copyright (C) 2021 by Costava
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
@nikita-skobov
Copy link

you should include some output

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