4 ms·
The warning is true - it is "at least" 10: char ten(char foo[static 10]); char ten(char foo[static 10]) { return foo[1]; } void generates_no_warn
by merlincorey 11y ago
The warning is true - it is "at least" 10:
char ten(char foo[static 10]);
char ten(char foo[static 10]) { return foo[1]; }
void generates_no_warning(void);
void generates_no_warning() {
char foo[30];
ten(foo);
}
int main() {
generates_no_warning();
}
Modified also so it would build cleanly with -Weverything -Werror
- uxcn 11y agoIt avoids stepping on memory elsewhere in the program though. My personal preference for C99 and above is to pass the length as a parameter. int do_stuff(size_t len, int64_t arr[len]); It still suffers from the pointer decay problem, but it at least forces whoever is reading/writing the code to acknowledge the length.