Random comment



  • Found this while trying to decipher some mildly WTF-worthy code. I'd love to know the story behind it.

    // FUCK THIS
    //	if (!(window->callback = callback))
    //		window->callback = def_callback_proc;
    


  • Hell, what's wrong with 'em young folk? Can't read good old C, the language of the bible, anymore?

     Ok, it's weird, but the test !(...) succeeds if the lvalue of assignment, which is callback, == NULL. So what it does is if (callback == NULL) window->callback = def_callback_proc; else window->callback = callback;

    I can understand you'd want to comment it out, but the swearing hints at things much fouler lurking around the corner.

     Hmm, in the mean time, I switched from movie western dialect to LOTR dialect...



  • You say it yourself: "Ok, it's weird, but...". If code is 'weird', that should be a red flag, right there.

    I sure do find

    window->callback = callback ? callback : def_callpack_proc;

    easier to understand, for one.



  •  I agree, this is the perfect use of ternary operator.  it is the easiest and most expressive in this case.



  • I tracked down the reason for the "FUCK THIS" comment. The simplicity of the commented-out code masks the real WTF: the person who originally wrote the code considered pointers and ints to be the same thing, so the code produces the following message when uncommented and compiled:

    Error: invalid conversion from 'long int (*)(OpaqueWindowPtr*, UINT, WORD, LPARAM)' to 'long int (*)(long int, UINT, WORD, LPARAM)'


  • @Carnildo said:

    I tracked down the reason for the "FUCK THIS" comment. The simplicity of the commented-out code masks the real WTF: the person who originally wrote the code considered pointers and ints to be the same thing, so the code produces the following message when uncommented and compiled:
    Error: invalid conversion from 'long int (*)(OpaqueWindowPtr*, UINT, WORD, LPARAM)' to 'long int (*)(long int, UINT, WORD, LPARAM)'
    And that'll break if compiled for WIN64, too.


  • @alegr said:

    @Carnildo said:

    I tracked down the reason for the "FUCK THIS" comment. The simplicity of the commented-out code masks the real WTF: the person who originally wrote the code considered pointers and ints to be the same thing, so the code produces the following message when uncommented and compiled:

    Error: invalid conversion from 'long int ()(OpaqueWindowPtr, UINT, WORD, LPARAM)' to 'long int (*)(long int, UINT, WORD, LPARAM)'
    And that'll break if compiled for WIN64, too.

    Well yes, "OpaqueWindowPtr *" is part of Carbon, a MacOS X API.



  • I have the sneaking suspicion, having dealt with similar (or was it the same?) code a number of years back, the user might have wanted some code more like this:

    // {person's surname} blew away the callback every time into this function.
    // Rather than set first and determine if we had a value, only set if we do have a value.
    // Remember to test your code before you commit, {person's surname}.
    	if (callback)
    		window->callback = callback;
    

    Edit: Ok.  Apparently not.  Some people are apparently quite a bit more special than I know.


Log in to reply