I recently fixed a bug that was the result of something like
const char *arr[] = {
"string1", //some comment
"string2",
"string3" //another comment
"string4",
"string5"
};
i.e. someone forgot a , after "string3", and "string3" and "string4" gets pasted together. Now, while this is perfectly legal code, is there a gcc warning flag, or other tool that could scan the code base for similar errors ?
A basic 'tool' you could use is a preprocessor hack, but it's a very ugly solution:
#include <stdlib.h>
#include <stdio.h>
int start = __LINE__;
const char *arr[] = {
"string1", //some comment
"string2",
"string3" //another comment
"string4",
"string5"
};int end = __LINE__;
int main(int argc, char **argv){
printf("arr length: %zu\n", sizeof(arr) / sizeof(arr[0]));
printf("_assumed_ arr length: %d\n", (end - start - 2));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With