https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122312
--- Comment #1 from Alejandro Colomar <[email protected]> --- The benefit is being able to use nested functions knowing they'll be safe, regardless of whether the compiler optimizes or not. The following code uses nested functions to implement a QChar-aware version of strtol(3). It would be good to make sure that it doesn't require a writable stack by using 'static'. alx@devuan:~/tmp$ cat qchar.c #include <stdlib.h> #define QChar_of(s) typeof \ ( \ _Generic(s, \ const char *: *(const char *) "", \ const void *: *(const char *) "", \ char *: *(char *) "", \ void *: *(char *) "" \ ) \ ) #define my_strtol_(counter, QChar, ...) \ ({ \ long \ (strtol_ ## counter)(QChar *s, QChar **endp, int base) \ { \ return strtol(s, (char **) endp, base); \ } \ \ (strtol_ ## counter)(__VA_ARGS__); \ }) #define my_strtol(s, endp, base) my_strtol_(__COUNTER__, QChar_of(s), s, endp, base) int main(void) { char *s1 = "1"; const char *s2 = "2"; my_strtol(s1, &s1, 0); my_strtol(s2, &s2, 0); } alx@devuan:~/tmp$ gcc -Wall -Wextra qchar.c alx@devuan:~/tmp$
