6 ms·
Will this work? define string_length(x) _Generic(x, \ const char * : strlen((const char*)(const void*)x), \ struct MyStri
by nstbayless 3y ago
Will this work?
define string_length(x) _Generic(x, \
const char * : strlen((const char*)(const void*)x), \
struct MyStringBuffer * : ((const MyStringBuffer*)(const void*)x)->length)
- kelnos 3y agoHeh, this was my first thought as well, and it does indeed compile and work (with GCC 12.2, anyway).
- panzi 3y agoYeah, this is what I saw in some example code. Also you don't need the (void*), at least not with clang or GCC trunk on compiler explorer: https://godbolt.org/z/a8rP91dKr https://godbolt.org/z/a8rP91dKr
- deleted 3y ago[deleted]