Quick actions

cmd+k|ctrl+k

Navigation

Languages

Stupid DIY sizeof

Snippet info

Language

C

Visibility

public

Author

lazyshpee

Created

2019-11-13T14:23:18Z

Updated

2019-11-13T15:26:37Z

#include <stdio.h>

#define SIZEOF(type) ((char *)(&((type[0]){}) + 1) - (char *)(&((type[0]){})))
#define FMT(type) "SIZEOF(" #type ") == %ld\nsizeof(" #type ") == %d\n", SIZEOF(type), sizeof(type)

int main(void) {
    printf(FMT(char));
    printf(FMT(int));
    printf(FMT(float));
    printf(FMT(double));
    printf(FMT(long));
    printf(FMT(long double));
    printf(FMT(void *));
    
    return 0;
}
INFO