4 ms·
| The unused parameter warning is one of the biggest offenders in this area. And if you have a hundred warnings for unused parameters, which ones do you pay att
by queensnake 16y ago
| The unused parameter warning is one of the biggest offenders in this area. And if you have a hundred warnings for unused parameters, which ones do you pay attention to?
Well, so then you're exposed to this error. Do:
void foo(int x)
{
(void)x;
}
to silence unused parameter warnings.
- tptacek 16y agoGo look at Google code search, which includes vast quantities of code written by professional teams and (often later) open sourced. Very little of it casts expressions to (void). When I started at Arbor, I got rid of all the (void) casts. What an eyesore. Very little C code is const-correct either. Most of the C devs I know make fun of const-correctness.
- humbledrone 16y ago| What an eyesore. It's only an eyesore if you don't acknowledge the benefits that strict warnings can bring to the table. | Most of the C devs I know make fun of const-correctness. I for one don't mind putting in a tiny bit of upfront effort so that my compiler can double-check my work. Do the C devs you know also make fun of assert?
- tptacek 16y agoI don't acknowledge the benefits of casting things to (void). Therefore: definitely an eyesore. And, no. Nobody makes fun of assert. Which rather makes my point for me.
- ehnus 16y agoIf assertions disappear in certain optimized builds then what do you do, or recommend, to deal with warnings related to unused parameters or values if you don't believe that casting to void has value?
- scott_s 16y agoAs I pointed out above, in gcc you can explicitly mark variables as potentially unused.
- ehnus 16y agoAnd what do you suggest for MSVC, which doesn't support attribute unused or have any comparable declspecs?
- scott_s 16y agoIf what you say is true, then you have to either put up with the warnings, compile at a level that doesn't have the warnings, or figure out a hack around them - I don't like any of those options. I'm not as dogmatic as some others are in the thread. I just think it's a good idea to be warned when a variable is unused, enough that I'll mark my very few that might be #ifdef'ed out. If you're using a compiler that doesn't let you mark variables as such... well that sucks. You do what you can.
- tptacek 16y agoI don't understand how the question you ask even follows from the premise you forwarded. The fact that memset is probably always dead code here is why it's not really a bug. The fact that warnings about unused return values are useless 100-1000 times for every time they're potentially useful is why I don't litter my code with pointless casts.
- s3graham 16y ago(void)x does not work on all compilers to silence the warning. gcc + cl != C.
- chbarts 16y agoWhat's cl?
- scott_s 16y agoIf you're using gcc, you can say __attribute__((unused)): http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Variable-Attributes.html http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Variable-Attribu...
- josephruscio 16y agoYour compiler may offer a more formal way to indicate that it's acceptable for a parameter to be unused. In gcc it's an attribute: int foobar(int foo, int bar __attribute__((unused))) { /* Code that does not use bar */}