• Officer Johnny Holzkopf (unregistered)

    void setFrist(int x) { x = FILE_NOT_FOUND; } /* TODO: optimize */

  • akozakie (unregistered)

    I have yet to see a function as clearly justifying the keyword "void" as this one.

  • Bob (unregistered)

    But it's so optimal! The compiler will remove the function and calls to it as the function does nothing.

  • TheCPUWizard (unregistered)

    Really?

    class Foo { public: Foo& operator=(const double t) {} };

    #define int Foo&

    void Bar(int x) { x = 0; }

  • Registered (unregistered)

    It was cleared, if only for a moment before exiting or being optimized away.

  • (nodebb)

    Every comment atm is held for moderation. Clearly commenting has been implemented using this function. I bet this will also be moderated.

  • Sauron (unregistered)

    That function... could actually be clearing some data (or more specifically overwrite some junk memory) as a side-effect, as some stuffs would be written on the memory stack when the function is called (the value of some CPU registers would be saved there, and the memory for the local variable x would also be allocated there), and that would overwrite whatever data there was in the few bytes of memory involved.

    But if the goal is to reset a few bytes of memory, then that's an absolutely insane way to do it (and possibly unreliable and dependent on whether the compiler decides to nuke the function entirely for optimisation purpose since it doesn't do anything useful).

    My guess is that it is something darker than just a very dirty hack. A tormented soul, scarred by the evil of a giant corporation, entered a mad trance, and unleashed on their keyboard every crazy raving that formed into their mind. Like bloodstains, many WTFs remained in the codebase, like tragic traces of the murder of the coder's sanity.

  • (nodebb) in reply to mynameishidden

    I bet this will also be moderated.

    Nope. Or, if it was, it exited the queue before all the comments before it.

  • (nodebb)

    My first thought was, OK, this is a newbie who hasn't wrapped their head around "pass by value" versus "pass by reference". It can seem weird that modern languages like C# would take an integer by value, but an object instance by reference, even though the code looks the same in both cases.

    But this is C, not C#, which doesn't have pass by reference (hence Remy's comment about using a pointer). Even C++ takes objects by value, unless specified otherwise, which in my opinion seems to be one of a number of mistakes that more modern languages learned from.

  • Dr, Pepper (unregistered)

    Paid by the line? I can call "clearVal" anywhere I want and not worry about it affecting the code. If I'm being paid by the line, then I'm going to call clearVal everywhere I can.

  • (nodebb) in reply to jeremypnet

    Nope. Or, if it was, it exited the queue before all the comments before it.

    Maybe x was already 0 when mynameishidden posted the comment???

  • Duston (unregistered)
    Comment held for moderation.
  • Oracles (unregistered)
    Comment held for moderation.
  • Randal L. Schwartz (github) in reply to Registered

    Schroedinger's Zero.

  • Foo AKA Fooo (unregistered) in reply to prueg
    Comment held for moderation.
  • (nodebb) in reply to prueg

    You have to be careful, because what is called a reference in C# is actually a pointer in C. A reference in C++ for example, is a pointer that has to be initialized and cannot be changed. So I don't know why "reference" was chosen for managed pointers in C#, I think it they followed Java and Java renamed 99% of terms for marketing reasons (like they called their interpreter VM, because interpreters were rightfully considered slow and inefficient), so I wouldn't be surprised that it makes actually no sense. Oh and the only difference between a managed and an unmanaged pointer is basically that an managed pointer includes a type reference to identify the object and is handled via garbage collection.

  • (nodebb)

    This actually doesn't seem so evil if you figure it once did something useful.

  • Foo AKA Fooo (unregistered) in reply to MaxiTB
    Comment held for moderation.
  • Ulli (unregistered)
    Comment held for moderation.
  • (nodebb)

    That some poor noob wrote that isn't really a WTF. We all had to learn at some point and make stupid mistakes.

    The TRWTF is that this was still in the codebase for someone to find. I have no idea how old is that codebase. It denotes a clear lack of peer review in check ins.

  • Jaloopa (unregistered)
    Comment held for moderation.
  • Maurizio (unregistered) in reply to MaxiTB

    "like they called their interpreter VM, because interpreters were rightfully considered slow and inefficient" : actually, no, the term was already in use for similar architecture (compilation to intermediate code, execution of the intermediate code by an interpreter or compiler). Search for p-code virtual machine.

    Maurizio

  • (nodebb) in reply to Maurizio

    I'm aware of the history; I lived through it. Back then the term virtual machine was exclusively used for, well, real virtual machines. And a p-code machine is not called virtual machine, just p-code machine. And that's nothing special, nor is intermediate code, every interpreter i know used them long before Java and no, nobody called them virtual machines before ;-).

  • Iterator (unregistered)
    Comment held for moderation.
  • (nodebb) in reply to prueg
    Comment held for moderation.
  • Craig (unregistered) in reply to prueg
    Comment held for moderation.

Leave a comment on “Clear This”

Log In or post as a guest

Replying to comment #:

« Return to Article