- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
oh crap, do everyone a favor and look into your compiler manual.
there's an actual need for unused parameters in C ocasionally. especialy when you start throwing around function pointers and you need all the functions to have the same signature (like the interupt vector table.
#pragma unused(a) works with some compilers, variations of taht work on others.
Admin
Wouldn't a better (and warning-free) solution be:
#define ever ;; for(ever){ // Code goes here }
Admin
Warnings are good, Warning messages would stop this WTF from ever existing.
Also QString from what I can understand, is a class from the Qt library (cross platform libray). QString reference
Admin
Admin
a;
does the trick. At least with VS2003.
We use it all the time when providing default implementation of some interface. We don't necessarly use all the parameters in that implementation, but they are there for a reason and some other implementation of this interface will use them.
Admin
It seems like in the modern world with classes and overloading, (x)=(x) isn't a good idea, because it can have side effects. Suppose X is a string - there's no way the compiler could know it doesn't have to do that. And I bet a fair number of classes have bugs where x=x would cause a segfault, because they delete their own data, then copy the other object's (now just-deleted) data.
So either cast to void (which I guess could still have side effects, but who would overload that cast in practice?), or just don't give the argument a name. (e.g. f(int x, int /* unused */) { ... }
Admin
You should try the World of Warcraft forums...
Oh, and I only consider a piece of code correct if it has no warnings, if only because it gets harder to detect real problems if you have a lot of warnings. Going from 0 to 1 warning is a lot easier to notice as going from 300 to 301.
Admin
I thought you could just declare them without a name, eg.
void func1(int n) { // Warning, "n" not used }
void func2(int) { // No warnings }
Admin
is better, it doesn't generate warnings on most compilers.
Admin
I had a roommate in college that smoked, and his favorite warning was about the smoke being harmful to non-smokers. His answer was "It's a good thing I'm not a non-smoker".
Admin
I call BS on this CodeSOD. While the code is obviously wrong, I don't believe you that it will actually cause any conforming C++ compiler to warn. QString is a class type, thus a variable of type QString is always initialized, in this case, it's initialized with the default constructor, which constructs a null QString (the same thing you'd get by copying QString::null, it's a QString which satisfies both isNull and isEmpty, a null QString is always empty, an empty QString is not always null). Thus, this code silently returns an empty string, with no warning whatsoever. I can only assume the original snippet was different than what was posted, maybe the variable was a char * or something rather than a QString?
Admin
Kevin, did it occur to you that perhaps the warning was about the actual unused variable ipv4Addr?
CAPTCHA: Prove that you're a robot. Type in the word you see in the image without misspelling it.
Admin
Oh, you have a good point there. ;-)
Admin
Doesn't Need Specifying?
Admin
Wait, the real warning here is an unnecessary named variable!
QString HostAddress::dns () const { Q_UINT32 ipv4Addr = getIpv4Address(); return QString(); }
Anonymous rules!
...
Oh, wait. That's in lisp. In real languages, it doesn't....
Admin
Why? Just change the function definition to
and you'll get rid of the unused parameter warning WITHOUT the need to change the rest of your code. And you won't leave the maintainers of your code scratching their heads for hours trying to figure out why you wrote "a=a;" etc. there.
If the functions signature doesn't change, there is no need to change anything in the caller. Callers are still required to call this function with 3 parameters of type 'int'.
It won't happen. The caller still calls the function with Still the same call. Since these 3 parameters are considered used (because they're used as argument in some function call), the compiler won't complain that p/q/r is unused. It's a quick no-risk change. The only risk is you: you don't understand how to change it in a correct way. So, you're going to introduce the risks of changing a large bunch of code lines sprinkled around many files UNNECESSARILY! const-ness has to be planned ahead very carefuly and skillfully. Adding 'const' as an afterthough can easily break working code.Admin
I can't agree more. Maybe, compiler writers should start considering including suggestions in the warning messages, so that those clueless people can learn the correct way to code.
e.g.
Admin
Btw, the correct way to do it would be:
int doSomeStuff( int, int, int) { }
p.
Admin
trrhrzkm http://qltzugvv.com bkgbtewc cwhxfyap