Skip to content

Instantly share code, notes, and snippets.

@cmcbride
Created May 18, 2011 05:07
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 cmcbride/978023 to your computer and use it in GitHub Desktop.
Save cmcbride/978023 to your computer and use it in GitHub Desktop.
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
void
print_size( char const * const desc, const size_t size )
{
printf(" %10s: %zu bytes\n", desc, size);
}
#define PRINT_SIZE(T) print_size(#T, sizeof(T));
int
main ( void ) {
printf("Sanity checks for reference:\n");
PRINT_SIZE(int32_t);
PRINT_SIZE(int64_t);
puts("");
PRINT_SIZE(size_t);
PRINT_SIZE(ssize_t);
// PRINT_SIZE(ptrdiff_t); // an alternative to ssize_t
puts("");
PRINT_SIZE(int);
PRINT_SIZE(short);
PRINT_SIZE(long);
PRINT_SIZE(long long);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment