the command "what" is used on my project to query some peaces of informations about executables (compilation date, version, ...). I am fixing a bug where one line is missing in what output since we have changed the version of gcc. The string was defined in a local scope:
char string_for_what = "@(#) Component comp1";
This string was never used. I assume the optimizer has removed it.
I think the normal correction should be to declare the string at a global scope. But what prohibits a future compiler to optimize it away if it is not used ?
I have thought about calling strlen("@(#) Component comp1")
to ensure that the string is used, but it seems that clang is optimizing away this call on constant strings.
Shoud I call fopen("@(#) Component comp1")
? If someone creates a file with this name, I may lose one file descriptor. This seems to work but it seems also a bit overkill.