silence unused variable warning#265
Conversation
gcc 16 got smarter and now complains about the (intentionally) unused variable: run.c:1981:13: warning: variable 'unused' set but not used [-Wunused-but-set-variable=] This variable appears to have been added solely to silence an unused return value warning. I'm not sure what combination of warning flags, compiler, and OS on which that was the case, but I believe a cast to void is the intended way to silence such warnings. Trying to trick the compiler about a variable being used seems like a losing battle.
|
I am pretty sure that was my code. With some earlier version of gcc casting to void didn't work, as I said in the comments. Compilers are getting "too" smart. Bleah. Thanks for the patch. |
I am a bit curious about where you encountered that. Do you know which operating system you encountered that error on? I tried a few gcc versions, but I didn't see the warning even with |
Indeed, that is the case on my system. Interestingly, using a cast to void with gcc 16 there is no warning, but with the stock gcc (13.x) it does warn. Once again: bleah. :-( (I'm on Ubuntu 24.04) |
Ah, I see. I found a lengthy and heated discussion about this here: I can't explain why you're seeing the warning go away with gcc 16, though. Another option mentioned in the comments there is if (wctomb(NULL, L'\0')) { /* silence unused result warning */ }but my preference is just the void cast, especially if it works with gcc 16. |
|
@michaelforney I sorta skimmed that discussion. Amazing that it went on for NINE YEARS! Sheesh. FWIW, the other option to deal with GCC is use |
gcc 16 got smarter and now complains about the (intentionally) unused variable:
run.c:1981:13: warning: variable 'unused' set but not used [-Wunused-but-set-variable=]
This variable appears to have been added solely to silence an unused return value warning. I'm not sure what combination of warning flags, compiler, and OS on which that was the case, but I believe a cast to void is the intended way to silence such warnings.
Trying to trick the compiler about a variable being used seems like a losing battle.