Sample Code
sizes.c
#include <stdio.h> /* printf */
#include <stdint.h> /* intptr_t */
int main(void)
{
int i = 123; /* sizeof(int) depends on architecture */
int *p1 = &i; /* works on all architectures */
intptr_t j = 456; /* intptr_t is a pointer-sized int */
intptr_t *p2 = &j; /* works on all architectures */
i = (int)p1; /* Probably works on 32-bit, may not on 64-bit */
j = (intptr_t)p2; /* Will work on either architecture */
printf("sizeof(char) : %lu\n", sizeof(char));
printf("sizeof(short) : %lu\n", sizeof(short));
printf("sizeof(int) : %lu\n", sizeof(int));
printf("sizeof(long) : %lu\n", sizeof(long));
printf("sizeof(long long) : %lu\n", sizeof(long long)); /* C99 */
printf("sizeof(float) : %lu\n", sizeof(float));
printf("sizeof(double) : %lu\n", sizeof(double));
printf("sizeof(long double) : %lu\n", sizeof(long double));
printf("sizeof(void*) : %lu\n", sizeof(void*));
printf("sizeof(size_t) : %lu\n", sizeof(size_t));
printf("sizeof(intptr_t) : %lu\n", sizeof(intptr_t));
return 0;
}
Outputs:
32-bit Microsoft/GCC/Cygwin
32-bit Clangsizeof(char) : 1 sizeof(short) : 2 sizeof(int) : 4 sizeof(long) : 4 sizeof(long long) : 8 sizeof(float) : 4 sizeof(double) : 8 sizeof(long double) : 12 sizeof(void*) : 4 sizeof(size_t) : 4 sizeof(intptr_t) : 4
64-bit Microsoft (LLP64)sizeof(char) : 1 sizeof(short) : 2 sizeof(int) : 4 sizeof(long) : 4 sizeof(long long) : 8 sizeof(float) : 4 sizeof(double) : 8 sizeof(long double) : 16 sizeof(void*) : 4 sizeof(size_t) : 4 sizeof(intptr_t) : 4
64-bit MinGW (LLP64)sizeof(char) : 1 sizeof(short) : 2 sizeof(int) : 4 sizeof(long) : 4 sizeof(long long) : 8 sizeof(float) : 4 sizeof(double) : 8 sizeof(long double) : 8 sizeof(void*) : 8 sizeof(size_t) : 8 sizeof(intptr_t) : 8
64-bit Clang/GCC (Linux/Mac LP64)sizeof(char) : 1 sizeof(short) : 2 sizeof(int) : 4 sizeof(long) : 4 sizeof(long long) : 8 sizeof(float) : 4 sizeof(double) : 8 sizeof(long double) : 16 sizeof(void*) : 8 sizeof(size_t) : 8 sizeof(intptr_t) : 8
Warning:sizeof(char) : 1 sizeof(short) : 2 sizeof(int) : 4 sizeof(long) : 8 sizeof(long long) : 8 sizeof(float) : 4 sizeof(double) : 8 sizeof(long double) : 16 sizeof(void*) : 8 sizeof(size_t) : 8 sizeof(intptr_t) : 8
sizes.c:12:7: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]