Sizeof Reference

C variable sizes:

[email protected]:~/C$ uname -a
Linux ubuntu-laptop 4.11.0-041100-generic #201705041534 SMP Thu May 4 19:36:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[email protected]:~/C$ cat /etc/issue
Ubuntu 16.04.2 LTS \n \l

[email protected]:~/C$ cat sizeof.c 
#include <stdio.h>
#include <string.h>
#include <stdbool.h>   // bool
#include <sys/types.h> // u_char
#include <stdint.h>    // uintN_t
#include <unistd.h>    // getpagesize()
#include <sys/user.h>  // PAGE_SIZE


int main()
{

	printf("bool         : %lu byte(s)\n", sizeof(bool));
	printf("char         : %lu byte(s)\n", sizeof(char));
        printf("u_char       : %lu byte(s)\n", sizeof(u_char));
        printf("uint8_t      : %lu byte\n",    sizeof(uint8_t));
        printf("uint8_t*     : %lu byte\n",    sizeof(uint8_t*));
	printf("short        : %lu bytes\n",   sizeof(short)); 
	printf("int          : %lu bytes\n",   sizeof(int));
        printf("float        : %lu bytes\n",   sizeof(float));
	printf("uint32_t     : %lu bytes\n",   sizeof(uint32_t));
        printf("uint32_t*    : %lu bytes\n",   sizeof(uint32_t*));
        printf("void*        : %lu bytes\n",   sizeof(void*));
	printf("long         : %lu bytes\n",   sizeof(long));
        printf("char*        : %lu bytes\n",   sizeof(char*));
        printf("size_t       : %lu bytes\n",   sizeof(size_t));
        printf("uint64_t     : %lu bytes\n",   sizeof(uint64_t));
	printf("double       : %lu bytes\n",   sizeof(double));
        printf("long long    : %lu bytes\n",   sizeof(long long));
	printf("long double  : %lu bytes\n",   sizeof(long double));

        printf("PAGE_SIZE    : %lu bytes\n",   PAGE_SIZE);
        printf("MAX_ORDER    : %d\n",          11);
        printf("PAGE_SIZE<<11: %lu bytes\n",   PAGE_SIZE<<11);
        printf("getpagesize  : %d bytes\n",    getpagesize());

	return 0;
}
[email protected]:~/C$ gcc -o sizeof sizeof.c 
[email protected]:~/C$ ./sizeof 
bool         : 1 byte(s)
char         : 1 byte(s)
u_char       : 1 byte(s)
uint8_t      : 1 byte
uint8_t*     : 8 byte
short        : 2 bytes
int          : 4 bytes
float        : 4 bytes
uint32_t     : 4 bytes
uint32_t*    : 8 bytes
void*        : 8 bytes
long         : 8 bytes
char*        : 8 bytes
size_t       : 8 bytes
uint64_t     : 8 bytes
double       : 8 bytes
long long    : 8 bytes
long double  : 16 bytes
PAGE_SIZE    : 4096 bytes
MAX_ORDER    : 11
PAGE_SIZE<<11: 8388608 bytes
getpagesize  : 4096 bytes

Previous page: Netmap Notes
Next page: Stack, Heap and Stack Frame