A file with just a const declaration, like so:
const int genericRC = 0;
when compiled with the clang C++ front end warns about this unused variable. However, the clang C front end is silent about this:
$ cat x.sh
clang -c src/x.c -Wall -std=c11
clang++ -c src/t.cpp -Wall -std=c++11
$ ./x.sh
src/t.cpp:1:11: warning: unused variable 'genericRC' [-Wunused-const-variable]
const int genericRC = 0;
^
1 warning generated.
Is there any fundamental difference in C vs. C++ const for const static scoped variables of this sort, or is this just a warning that happens to be implemented in the clang C++ front end, but not in the C front end.
答案 0 :(得分:3)
In C++ this has internal linkage so the compiler can know it is unused. In C it has external linkage so it might be used from another translation unit, therefore it would be premature to warn.