- 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
It doesn't It's a constraint violation to apply sizeof to an incomplete type, and void is always an incomplete type. So there's no way to evaluate this.
(For the sake of argument, I assumed you meant "in C", because sizeof is a C keyword)
Admin
Hey, I had to do that in C one time!
Admin
How about sizeof(empty_class) in C++ where class empty_class{}; then? Trying to explain the empty class optimization gets interesting.
Admin
Looks like PHP to me :)
Admin
I sometimes like to use the parens, but mostly for syntactic uniformity with the other keyword constructs that do require it (e.g. if, while, for, switch, etc.) And yes, I do realize that those statements just require it to disambiguate where the controlled statement/block begins.
Admin
are you being serious? I come to the daily wtf for two reasons: the wtf itself, and the herds of idiots who reply, half of which don't really know why it's a "wtf" in the first place, but feel compelled to distance themselves from the "idiots" by answering.
Admin
C'mon give the guy some slack, I bet he was only kidding.
[image]
Admin
No chance.
I'm sure people really think this is good stuff. That's why they come to the site - to learn good stuff from the examples.
This post is all of the [image] approved.
Admin
In some functional languages this actually makes sense and will work, with a little nudge from the compiler. =D
Admin
I reckon someone should write a book compiling the best WTFs - some guy above is right about the polymorphic acronym, surely we're at a point now where we could get chapters about:
- pointless conversion code
- obvious return values
- blatantly missing conditionals
- comical exceptions
- Paula's bean
- advanced double click processing
- etc etc...
I can see it now, "Dave Gorman's Programmer-Whacking"
Admin
Admin
void pointers are used to access arbitrary bytes (or whatever the basic group of bits is on the machine) so they are the primitive group (1 byte) in size. void means, having no type.
Admin
That's just crazy talk. Prove it. (please?)
Admin
Admin
Your coworker is now officially Management material.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Admin
I dont know this. Is it wrong to call return_false()? Then why not?
Admin
It's PHP. Both in Perl and Bash you can't specify the arguments to functions on the function declaration itself.
This would be bash:
function somefunc {
echo $1 $2 $3
}
This would be perl:
sub somefunc {
my $var1 = shift;
my $var2 = shift;
print "$var1 $var2\n";
}
Admin
Mauritz said:
"Now explain why sizeof(void) == 1"
Cause it ain't.
To be serious, sizeof cannot be applied to an expression/type with a type that is incomplete. void is an incomplete type that cannot be completed. Since this is the case the compiler can do whatever it want really. sizeof(void) == 1 is one possiblity, compile error another. Runtime error is also allowed, but likely if the compiler is to be regarded as a serious product.
I hate it when people bring fact into the discussion...
Admin
It's possible that this code existed as the starting framework of an API that actually would perform some actions on the arguments, like validity checking or content filtering or somesuch, but the team was sacked before it had the chance to actually write the API.
I just defended a WTF.
Huzzah.
Admin
Admin
Gate said:
"because 'void' is a datatype.. and all types point to data of some sort.. even a void type must be 'at least' 1 byte. thus sizeof(void) == ( sizeof(__int8) || sizeof(char) )"
This is not quite right. GCC does this as an extension, and states in the documentation that it is not supported by the language proper. Try compiling with the -pedantic option to turn of language extensions.
If you Google for "n869 C" (without the quotes in the search field) the first link will give you the final draft of the standard. Look up section 6.5.3.4 for an explanation. Essentially, void is an incomplete type. Which means, oversimplified, that a pointer to it cannot be derefenced. sizof does not support incomplete types. Thus the behaviour is undefined so a compiler can do anything really.
Admin
Ah, good old sizeof(char)... the biggest WTF of all is the idiots who insist on writing things like
char *foo = (char*) malloc (100 * sizeof(char));
because "you can't assume that every computer has the same sized bytes".
(Well, the biggest WTF after this forum software. Hey, someone had to say it. I love these CAPTCHAs, they don't think I'm human. Probably my fault for typing in the word it actually displays, instead of whatever the fuck it thinks it's displaying.)
Admin
<FONT face="Courier New" size=2>function dont_return_anything($ANYTHING)
{
}</FONT>
<FONT face="Courier New" size=2>function dont_return()
{
while (1 != 1);
}</FONT>
Admin
Unfortunately yes. I'm working with a third party library (as in paid for) that is full of it. It drives me mad! Maybe it's so they can sell the library per source byte?
Admin
<FONT face="Courier New" size=2>"huzaah."</FONT>
Admin
In Java, this would be a perfectly normal set of methods to return data from a private object. A case statement would be completely wrong, in that context. Now this isn't Java, but I'm willing to make an allowance for someone who is obviously used to Java.
The last function is the one that leaves me scratching my head. That's not normal for Java, or anything else I know of.
Admin
My Bad.
Return false is completely ridiculous as well.
Admin
The function 'return_opposite_of_search_list' is used (I'll bet) as an optimization. The writer didn't want to have to write a function for return_false AND return_true. So, he would use it as:
// Didn't need to write 'return_true'; that would be crazy...
var itsTrue = return_opposite_of_search_list(return_false());
This might even work, if false == 0...
Admin
Actually, Black Holes are the total presence of a bunch of really, really compacted matter which warps space with its gravity so much that light cannot escape. They are there, they are very solid, and you really don't want to meet one in a dark alley after midnight (or at any time of day, come to think of it).
Admin
Admin
I think it's PHP - use of "function" and $ before variables
.
Why are they returning what the search list is not? They are breaking the logic! (That's logic that should be there, not that there is any)
Admin
public bool returnMaybe()
{
Random r = new Random();
return r.Next(100)%2 == 0;
}
Admin
There's a bug! they forgot the cases!!! :D
if($search_list ==null) return false;
else{if($search_list =='0') return true;
else {if($search_list >'0') return false;
else {if($search_list <'0') return false;
else return false;
}
}
}
return false;
Admin
I guess you forgot something: <font size="2">
function return_false()
{
return isTrue(!return_true());
}
function return_true()
{
return !isFalse(!return_false());
}
function isFalse($bool)
{
switch($bool){
default: return isTrue($bool==return_true());
}
}
function isTrue($bool)
{
switch($bool){
default: return isFalse($bool==return_false());
}
}
</font>
Admin
I don't know, but it's 0, so I guess it doesn't really matter.
Admin
<FONT size=2>function return_russian_roulette()
</FONT>{
$bullet = rand() % 6;
if($bullet == 4)
{
while(1 == 1);</FONT><FONT size=2>
}
return $bullet;</FONT><FONT size=2>
}
Admin
Nice! Buffer overflow. By the way, I took the liberty of fixing your open curly brace.
Admin
<FONT face="Courier New" size=2>cowabunga! *high five*</FONT>
Admin
I dissagree. It seems to me that he did know the concept of 'return' too well.
I have an other theory about why this happened:
Admin
Shouldn't dont_return be implemented like this:
<font face="Courier New" size="2">function dont_return()
{
while (1 == 1);
}</font>
Admin
What's wrong with the way the braces were before?
I used to do my curly braces the way you "corrected" them. But after having maintained a lot of messy C++ code, I've changed sides. I now put the opening curly brace on a new line. If the method gets long at all, or has a lot of indentation, or if some jackass has decided to use tabs instead of spaces.. the opening curly brace on its own line makes the code much much easier to decipher.
Although I should note, if it's a simple one line function like this (or like Java getters and setters), I'll typically do it like this-
<font size="1">public int getXxx () { return xxx; }
public void setXxx (int xxx) { this.xxx = xxx; }</font>
Admin
[late-night infomercial]
Have you ever had the need for an infinite loop but couldn't find a developer who could really crash your runtime the way you want it crashed? Well, you're in luck! Kipthegreat is a "specialist" who can provide you with one, in any flavor of your choosing. Just send $59.99 and a 3.5 floppy in a SASE to:
Kip the Great
c/o TheDailyWTF.com
1000 W. Alameda Blvd.
Burbank CA 91522
Admin
Nothing was wrong with them. I just bumped them up to the line of the control structure definition. I was just being a goof.
Admin
function definition, rather.
Admin
It's a stack overflow.
Admin
Does Kipthegreat give seminars? I need to sign up.
Admin
Was there any unit-testing code involved? This looks like someone was using test-driven development and just stopped at the fake-the-function-up-to-make-the-test-work-the-first-time stage.
Admin
damn! C + Linux = buffer overflows on the brain.
Admin
They had a year. Here is the starting sentence:
Diogo is part of a "specialist" team that was brought in to replace a handful of other developers who had spent the past year or so unsuccessfully building an accounting system.
Sincerely,
Gene Wirchenko
Admin
Absolutely. The weekend of December 2-4, 8am-6pm (lunch not provided) at the Miami-Dade County YMCA! Sign up now!
On day 2 of the seminar I'll go over move advanced ifinite looping, utilizing the for-switch design pattern. Can you spot the impossible cases in this code? I bet your manager who pays you per KLOC can't.
<font size="1">for (int i = 0; i < 10; i++)
{
switch (i)
{
case 0:
i *= 1;
case 1:
i--;
break;
case 2:
i = 7;
break;
default:
i++;
break;
}
}</font>