Skip to content

Instantly share code, notes, and snippets.

@schaeferpp
Created September 30, 2015 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schaeferpp/3b4f2b5641851422acb1 to your computer and use it in GitHub Desktop.
Save schaeferpp/3b4f2b5641851422acb1 to your computer and use it in GitHub Desktop.
C-Datatype sizes
/******************************************************************************
*
* file: main.c
* date: 2015-09-30
* author: Paul Schaefer
*
* Print some datatype sizes
*
*****************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <sys/types.h>
#include <limits.h>
#define PRINT_SIZE(TYPE) (printf ("%15s: %2ld bytes\n", #TYPE,\
(unsigned long) sizeof (TYPE)))
int
main (int argc, char *argv[])
{
(void) argc;
(void) argv;
printf ("Basic datatypes\n");
PRINT_SIZE (short);
PRINT_SIZE (unsigned short);
PRINT_SIZE (int);
PRINT_SIZE (unsigned int);
PRINT_SIZE (long);
PRINT_SIZE (unsigned long);
PRINT_SIZE (double);
PRINT_SIZE (float);
printf ("\nExplicit datatypes\n");
PRINT_SIZE (int8_t);
PRINT_SIZE (int16_t);
PRINT_SIZE (int32_t);
PRINT_SIZE (int64_t);
PRINT_SIZE (u_int8_t);
PRINT_SIZE (u_int16_t);
PRINT_SIZE (u_int32_t);
PRINT_SIZE (u_int64_t);
printf ("\nMisc. datatypes\n");
PRINT_SIZE (size_t);
PRINT_SIZE (ssize_t);
PRINT_SIZE (off_t);
PRINT_SIZE (__WORDSIZE);
printf ("\nWordsize: %ld bit\n", __WORDSIZE);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment