Getting C++ inspections for a C project
Hey after working with C++ I now want to give C a try and started learning it. I created a C 23 project in CLion and started experimenting with the language. But one thing I noticed, I am getting C++ inspections even though the project is regocnized as a C project by CLion.
For instance I get these warnings / suggestions:
“Variable can be made constexpr”
“Zero constant can be replaced with nullptr”
“Type can be replaced with auto”
But of course all of these are C++ language keywords so they won't work in C. One solution would probably be to disable the inspections but as I also like to continue working on C++ projects this is not really an option.
Isn't there a way to get only C-related inspections in C projects and still be able to get C++ inspections in C++ projects?
Please sign in to leave a comment.
Hello!
File | Settings | Advanced Settings
. Sorry for the inconvenience, right?Hey - thank you for your response! I have ReSharper C++ language engine enabled since it is available.
the most simple way to reproduce:
1. create a new C23 project.
2. in main.c add a static const variable
3. make sure to use it somewhere in the main function
4. notice how the suggestion: “Variable 'test' can be made constexpr”
int main(void)
{
static const bool test = false;
if ( test )
return 1;
return 0;
}
Thank you for the provided example!
C23 actually supports the constexpr specifier - https://en.cppreference.com/w/c/language/constexpr.