CLion C - Warns about assigned but never accessed volatile
I'm working on some very low level Freestanding C Code in CLion. Part of my RESET Function (which has many complaints, but I'm ignoring them because I shouldn't be doing what I'm doing, but its valid anyways) assigns a volatile extern global called __counter_enable. CLion is complaining that it is assigned but never accessed. This should not be a warning (as it is Observable Behavior according to the C Standard), and may in fact have meaning outside. In this case, the assignment to 0 ensures that after a Soft-Reset (Rather than a reset from power-on), the enable flags are zeroed. I can ignore this, however in general, it should not be a warning to assign to a volatile, even if its never read in code, as nothing can be certain of the side-effects of writing to a volatile. In this case, it is writing to an on-console flags register.
Please sign in to leave a comment.
Hi!
What CLion version do you use? Do you have all flags enabled in File | Settings | Languages & Frameworks | C/C++ | Clangd? Could you please provide the screenshot of the warning?
These are the flags in that section: -Wno-unused-variable,-Werror=implicit-function-declaration,-Wshadow,-Wno-shadow-field-in-constructor-modified,-Wno-shadow-ivar. The CLion Version is 2019.2.4, Ultimate License.
This is an example of the warning. As I stated, it is marked volatile, and in this case, indeed, simply assigning it has side effects (enabling various automatic operations, including the automatic read of the console joypads, and Nonmaskable interrupts on Vertical Blanking)