Dear C Lazy Web,
How do I define an array of nonstring char arrays?
just a char array, valid:
char str[4] __attribute__((nonstring)):
array of char arrays, cursed:
char multi[10][4] __attribute__((nonstring));
I've tried typedefs and moving the attribute around. No luck. What am I missing?
Here's a godbolt:
https://godbolt.org/z/4Mb61heG1
I'd want to see a warning for both strlen() instances...
@kees You can always wrap it in in a struct, but maybe you consider that cheating? https://godbolt.org/z/jdacMT9MK
@uecker @vegard Maybe that's the solution: the attribute needs to be able to be applied to multidimensional char arrays. Without this, I can't fully apply my proposed fix of -Wunterminated-string-initialization to the Linux kernel (which has multidimensional arrays of C strings in some places and multidimensional arrays of non-strings in other places).
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117178
https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=dev/v6.13-rc2/truncated-nonstring&id=2618dfca21ab2b38484908efbe94e5d17c7dee3b