• (cs) in reply to Maurits
    Maurits:
    Now explain why sizeof(void) == 1

    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)

  • Mike (unregistered) in reply to Jim Koche

    Anonymous:
    i think he forgot

    function do_nothing()
    {
       return;
    }

    Hey, I had to do that in C one time!

  • Boojum (unregistered) in reply to seebs
    seebs:
    Maurits:
    Now explain why sizeof(void) == 1

    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)

    How about sizeof(empty_class) in C++ where class empty_class{}; then? Trying to explain the empty class optimization gets interesting.

  • Theo (unregistered) in reply to ferrengi
    ferrengi:

    Also, what language is this written in anyway?


    Looks like PHP to me :)
  • Boojum (unregistered) in reply to Gene Wirchenko
    Gene Wirchenko:
    Sonic McTails:
    Wow, it's like the orginial programmer didn't know the concept of 'return' ...

    I'd love to see the code that calls it.



    That is not as rare as you might think.  Have you ever seen
    <font size="2">     return(0);</font>
    ?  I have had people "explain" to me that the parens are needed when the return function is called.

    Sincerely,

    Gene Wirchenko

    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.

  • Oisin G. (unregistered) in reply to rikkus

    rikkus:
    What's wrong with this? How else are you going to get the value of false over SOAP? You need a function to call!

    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.

     

  • elgoog (unregistered) in reply to Oisin G.
    Anonymous:

    rikkus:
    What's wrong with this? How else are you going to get the value of false over SOAP? You need a function to call!

    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.



    C'mon give the guy some slack, I bet he was only kidding.
    [image]


  • Kiss me, I'm Polish (unregistered) in reply to elgoog
    Anonymous:
    Anonymous:

    rikkus:
    What's wrong with this? How else are you going to get the value of false over SOAP? You need a function to call!

    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.


    C'mon give the guy some slack, I bet he was only kidding.


    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.
  • (cs) in reply to kipthegreat
    kipthegreat:
    <font size="2">function return_false()
    {
      return !return_true();
    }


    function return_true()
    {
      return !return_false();
    }
    </font>

    In some functional languages this actually makes sense and will work, with a little nudge from the compiler. =D
  • (cs)

    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"

  • whome (unregistered) in reply to Manni
    Manni:
    Maurits:
    Manni:

    Well now we're going to open up a debate about the existence of "Nothing", and if it truly does exist, then how can it be nothing? Nothing is the absence of something, so to return SOMETHING, even if it's called NOTHING, means you are not truly returning NOTHING, and therefore have rendered the name of the function invalid. I totally just started bleeding from the ears trying to wrap my mind around that concept.



    Now explain why sizeof(void) == 1

    Think of it like a black hole. It's the complete absence of anything, but then again, nothing else can exist in the same location as a black hole. Therefore, it is actually taking up some kind of space. The original designers of C were able to look ahead and realize that their code might be run on black holes. Geniuses, I swear.

    I purposely avoided the word "brilliant" in my post because I didn't want to be one that guy.

  • (cs) in reply to Maurits
    Maurits:
    Manni:

    Well now we're going to open up a debate about the existence of "Nothing", and if it truly does exist, then how can it be nothing? Nothing is the absence of something, so to return SOMETHING, even if it's called NOTHING, means you are not truly returning NOTHING, and therefore have rendered the name of the function invalid. I totally just started bleeding from the ears trying to wrap my mind around that concept.



    Now explain why sizeof(void) == 1

    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.

  • (cs) in reply to foxyshadis

    That's just crazy talk.   Prove it. (please?)

  • Jim Henson (unregistered) in reply to ferrengi
    ferrengi:
    Alex Papadimoulis:

    <font color="#000099">function</font> return_opposite_of_search_list($search_list)
    {
    <font color="#000099">if</font> ($search_list == <font color="#990000">'0'</font>) <font color="#000099">return</font> <font color="#999999">true</font>;
    <font color="#000099">return</font> <font color="#999999">false</font>;
    }


    So has anyone figured out where in the code "return_opposite_of_search_list" is used?
    What do they have in the search_list and why do they need the opposite?

    Also, what language is this written in anyway?
    I don't think I've ever seen it before. The function names do not contain a return type in the signature.

    - Dan

    It looks PHPish to me.  Perhaps Perl or Bash or one of those breeds.

  • Douggie (unregistered) in reply to LAUGHING
    Anonymous:
    LOL Ok my co-worker figured out why he does this.


     it is actually simple.

     this was written the day after his lobotomy.
     

    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>

  • cingh (unregistered) in reply to Douggie

    I dont know this. Is it wrong to call return_false()? Then why not?

  • Sybren (unregistered) in reply to Jim Henson
    Anonymous:


    It looks PHPish to me.  Perhaps Perl or Bash or one of those breeds.



    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";
    }

  • Thomas (unregistered) in reply to Maurits

    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...

  • (cs) in reply to Thomas

    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.

  • Gate (unregistered) in reply to Maurits
    Maurits:
    Manni:

    Well now we're going to open up a debate about the existence of "Nothing", and if it truly does exist, then how can it be nothing? Nothing is the absence of something, so to return SOMETHING, even if it's called NOTHING, means you are not truly returning NOTHING, and therefore have rendered the name of the function invalid. I totally just started bleeding from the ears trying to wrap my mind around that concept.



    Now explain why sizeof(void) == 1
     
    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) )
  • Thomas (unregistered) in reply to Gate

    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.

  • Foobar Binks (unregistered) in reply to Gate

    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.)

  • (cs) in reply to Kiss me, I'm Polish

    <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>

  • (cs) in reply to Gene Wirchenko
    Gene Wirchenko:
    Sonic McTails:
    Wow, it's like the orginial programmer didn't know the concept of 'return' ...

    I'd love to see the code that calls it.



    That is not as rare as you might think.  Have you ever seen
    <font size="2">     return(0);</font>
    ?  I have had people "explain" to me that the parens are needed when the return function is called.

    Sincerely,

    Gene Wirchenko



    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?

  • (cs) in reply to dhromed

    dhromed:
    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.

    <FONT face="Courier New" size=2>"huzaah."</FONT>

  • (cs) in reply to emptyset

    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.

  • (cs) in reply to Satanicpuppy

    My Bad.

    Return false is completely ridiculous as well.

  • (cs) in reply to Jim Henson
    ferrengi:
    Alex Papadimoulis:

    <font color="#000099">function</font> return_opposite_of_search_list($search_list)
    {
    <font color="#000099">if</font> ($search_list == <font color="#990000">'0'</font>) <font color="#000099">return</font> <font color="#999999">true</font>;
    <font color="#000099">return</font> <font color="#999999">false</font>;
    }


    So has anyone figured out where in the code "return_opposite_of_search_list" is used?
    What do they have in the search_list and why do they need the opposite?

    Also, what language is this written in anyway?
    I don't think I've ever seen it before. The function names do not contain a return type in the signature.

    - Dan

    It looks PHPish to me.  Perhaps Perl or Bash or one of those breeds.



    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...

  • James Ingram (unregistered) in reply to Manni
    Manni:
    Maurits:
    Manni:

    Well now we're going to open up a debate about the existence of "Nothing", and if it truly does exist, then how can it be nothing? Nothing is the absence of something, so to return SOMETHING, even if it's called NOTHING, means you are not truly returning NOTHING, and therefore have rendered the name of the function invalid. I totally just started bleeding from the ears trying to wrap my mind around that concept.



    Now explain why sizeof(void) == 1

    Think of it like a black hole. It's the complete absence of anything, but then again, nothing else can exist in the same location as a black hole. Therefore, it is actually taking up some kind of space. The original designers of C were able to look ahead and realize that their code might be run on black holes. Geniuses, I swear.

    I purposely avoided the word "brilliant" in my post because I didn't want to be one that guy.



    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).
  • (cs) in reply to Satanicpuppy
    Satanicpuppy:
    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.


    <font color="#000099">function</font> return_signature($SIGNATURE)
    {
    <font color="#000099">return</font> $SIGNATURE;
    }
    }<font>function</font> return_note($NOTE)
    {
    <font>return</font> $NOTE;
    }

    This is not returning a private data field...
    It is returning whatever parameter is passed to it.

    So, it would work just fine to do:
    var mySignature = return_note('signature');



  • (cs) in reply to ferrengi
    ferrengi:
    Also, what language is this written in anyway?
    I don't think I've ever seen it before. The function names do not contain a return type in the signature.


    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)

  • (cs) in reply to mrsticks1982
    mrsticks1982:
    Anonymous:
    travisowens:

    <font face="Garamond">I smell another IsTrue() method next</font>

    <font face="Garamond">This post is [image] approved</font>



    I actually thought about extending his implementation with something like:

    function return_true()
    {
        return true;
    }

    function return_true_if_false_and_vice_versa($true_or_false)
    {
        if($true_or_false == return_false())
           return return_true();
        else
           return return_false();
    }

     

    Can't forget the famous,

    function return_click2($click2)
    {
        if($click2)
           return return_true();
        else
           return return_false();
    }

     



    public bool returnMaybe()
    {
       Random r = new Random();
       return r.Next(100)%2 == 0;
    }
  • ZeoS (unregistered)
    Alex Papadimoulis:

    <font color="#000099">function</font> return_opposite_of_search_list($search_list)
    {
    <font color="#000099">if</font> ($search_list == <font color="#990000">'0'</font>) <font color="#000099">return</font> <font color="#999999">true</font>;
    <font color="#000099">return</font> <font color="#999999">false</font>;
    }


    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;




  • tdc (unregistered) in reply to kipthegreat
    kipthegreat:
    <font size="2">function return_false()
    {
      return !return_true();
    }


    function return_true()
    {
      return !return_false();
    }
    </font>

    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>
  • chudpi (unregistered) in reply to Maurits

    I don't know, but it's 0, so I guess it doesn't really matter.

  • (cs) in reply to tdc

    <FONT size=2>function return_russian_roulette()
    {
       $bullet = rand() % 6;
       if($bullet == 4)
       {
          while(1 == 1);
    </FONT><FONT size=2>
       }

       return $bullet;
    </FONT><FONT size=2>
    }

    </FONT>
  • (cs) in reply to kipthegreat
    kipthegreat:
    <font size="2">
    function return_false()
    {
      return !return_true();
    }


    function return_true(){
      return !return_false();
    }
    </font>


    Nice!  Buffer overflow.  By the way, I took the liberty of fixing your open curly brace.
  • (cs) in reply to Mung Kee

    Mung Kee:
    Nice!  Buffer overflow.  By the way, I took the liberty of fixing your open curly brace.

    <FONT face="Courier New" size=2>cowabunga!  *high five*</FONT>

  • Konstantinos (unregistered) in reply to Michael Casadevall
    Sonic McTails:
    Wow, it's like the orginial programmer didn't know the concept of 'return' ...

    I'd love to see the code that calls it.


    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:

    1. We have to present something to the Boss
    2. The Boss doesnt know how to code/review.
    3. The Boss recognises comments and blank lines so we cannot use them to make our code bigger
    4. We get paid by the nr of lines in the code
  • (cs) in reply to Rank Amateur
    Rank Amateur:

    <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>



    Shouldn't dont_return be implemented like this:

    <font face="Courier New" size="2">function dont_return()
    {
    while (1 == 1);
    }</font>
  • (cs) in reply to Mung Kee
    Mung Kee:
    kipthegreat:
    <font size="2">
    function return_false()
    {
      return !return_true();
    }


    function return_true(){
      return !return_false();
    }
    </font>


    Nice!  Buffer overflow.  By the way, I took the liberty of fixing your open curly brace.


    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>

  • (cs) in reply to kipthegreat
    kipthegreat:

    <font size="2">function return_false()
    {
      return !return_true();
    }


    function return_true()
    {
      return !return_false();
    }</font>


    kipthegreat:


    Shouldn't dont_return be implemented like this:

    <font face="Courier New" size="2">function dont_return()
    {
    while (1 == 1);
    }</font>


    [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


  • (cs) in reply to kipthegreat
    kipthegreat:
    Mung Kee:
    kipthegreat:
    <font size="2">
    function return_false()
    {
      return !return_true();
    }


    function return_true(){
      return !return_false();
    }
    </font>


    Nice!  Buffer overflow.  By the way, I took the liberty of fixing your open curly brace.


    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>



    Nothing was wrong with them.  I just bumped them up to the line of the control structure definition.  I was just being a goof.
  • (cs) in reply to Mung Kee
    Mung Kee:

    Nothing was wrong with them.  I just bumped them up to the line of the control structure definition.  I was just being a goof.


    function definition, rather.
  • heinzkunz (unregistered) in reply to Mung Kee

    Nice!  Buffer overflow.

    It's a stack overflow.

  • (cs) in reply to Mung Kee

    Mung Kee:
    kipthegreat:

    <FONT size=2>function return_false()
    {
      return !return_true();
    }

    function return_true()
    {
      return !return_false();
    }</FONT>


    kipthegreat:

    Shouldn't dont_return be implemented like this:

    <FONT face="Courier New" size=2>function dont_return()
    {
    while (1 == 1);
    }</FONT>

    [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

    Does Kipthegreat give seminars? I need to sign up.

  • Eric (unregistered)

    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.

  • (cs) in reply to heinzkunz
    Anonymous:
    > Nice!  Buffer overflow.

    It's a stack overflow.


    damn!  C + Linux = buffer overflows on the brain.

  • (cs) in reply to dhromed
    dhromed:
    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.


    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

  • (cs) in reply to Rank Amateur
    Rank Amateur:

    Mung Kee:
    kipthegreat:

    <font size="2">function return_false()
    {
      return !return_true();
    }

    function return_true()
    {
      return !return_false();
    }</font>


    kipthegreat:

    Shouldn't dont_return be implemented like this:

    <font face="Courier New" size="2">function dont_return()
    {
    while (1 == 1);
    }</font>

    [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

    Does Kipthegreat give seminars? I need to sign up.



    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>

Leave a comment on “Doing What You Say, Saying What You Do”

Log In or post as a guest

Replying to comment #:

« Return to Article