Relative Content

Tag Archive for cgccsizeofpreprocessor-directive

_Generic length-function fails when default: sizeof(x)/sizeof((x)[0])

Issue: Recently I learned about _Generic. In my attempt to use it as a generic length-macro I stumbled upon a weird issue. While LENA(x) works perfectly fine, the generic LEN(x) fails to compile unless I remove the default one. #include <stdio.h> #include <string.h> #define LENA(x) sizeof(x)/sizeof((x)[0]) #define LEN(x) _Generic((x), int : snprintf(NULL, 0, “%d” , […]