- 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
Ooh, new WTF meme!
Captcha (sorry, don't do this normally, but it's fitting here): pointer
Admin
Admin
Admin
Looks like someone is clobbering their this pointer and added a self pointer rather than fix the corruption. Tread carefully.
Admin
One possibility is that fnCERTlibDeinitialize takes a CERTLib*& rather than a CERTLib* and nulls out the parameter, though this could still be handled via a local rather than a field.
The Delphi "compat" idea still sounds more plausible to me.
Admin
Oh, ouch. Good catch.
Admin
Admin
Hmmmm.
Now that's bootstrapping!
Admin
If there aren't any posts yet, there's nothing to delete. 8=]
This CodeSOD also needs a 'Me' member. ('MyClass' apparently cannot be implemented in C++?)
Admin
Well, you could disable posting until one post is posted, but there wouldn't be much comments then é? :)
Admin
Well, obviously you need that. I mean, what if you go to deinitialize the object, and the object is deinitialized before you have the chance to deinitialize it? How would you even refer to it?
Obviously, you'd use self.
I think.
Right?
Admin
This line
is quite common in Javascript. It's useful when working with closures. For example:
Threw me through a loop the first time I encountered it.
Admin
I've seen a more creative way to fight "first" posts on some blog: the original poster adds a "first" comment himself right after posting the article. Trolls seem to go away when they see there is a "first" already there :)
Admin
I am he as you are he as you are me and we are all together. ... I am the walrus...
Admin
delete this;
Admin
I have seen this used before in conjunction with a Singleton pattern that was then inherited. So this way you have generic Actor pointers that may really be some super subclass of Actor.
That code was some fun stuff.
Admin
Strictly speaking, that wouldn't be schizophrenic; that would be a schizoid personality. Schizophrenia is a disease, or syndrome, or what have you, that was mis-named in around 1890, and even the originator of the name got annoyed by its abuse.
Speaking as someone who has had to bail out a true paranoid schizophrenic, I should know.
I'm sure somebody has mentioned this by now, but my guess is that the coder of this truly awesome snippet started life in Perl and moved on to C++ whilst leaving their brain cell behind. SysAdmins, doncha just love them?
(I'll go away and read the rest of the posts now. Sorry.)
Admin
This won't just confuse programmers. It'll confuse programs! The object has a circular reference to itself.
Try to clone the object A using a deep copy. Traverse object fields from A to A.self, which is also A! Keep going...
I'd love to see whether this will break a Garbage Collector. I think early early Java interpreters had similar problems with link lists.
Admin
C++ is not hard. Programmers are just soft.
And I hate to do this, but I've an itch at the base of my medulla:
(Using generally recognised coding standards for the member function.)
Isn't code review a beautiful thing?
Pass the spam ...
Admin
Wouldn't it be easier to enforce the Singleton pattern in the constructor? Use a static boolean flag, and throw an exception when a second object is declared.
Admin
class CERTlib { private: CERTlib* what; // Pointer to this CERTlib* kind; // Pointer to this CERTlib* self; // Pointer to this CERTlib* shit; // Pointer to this CERTlib* _this; // Pointer to this CERTlib* like; // Pointer to this CERTlib* retard; // Pointer to this CERTlib* _of; // Pointer to this CERTlib* write; // Pointer to this CERTlib* would; // Pointer to this
public CERTlib* Result() { return what->kind->_of->retard->would->write->shit->like->_this; // ? }
/// CAPTCHA : digdug : and still didn't find anything. }
Admin
Admin
How about if self is pointing to an old instance? Suppose the class is lacking a proper copy ctor. (Not too hard to imagine.) The self pointer would likely end up pointing to the source of the copy.
Maybe this is the programmer's equivalent to that song "I'm My Own Grandpa".
Admin
So does Objective-C for that matter.
Admin
You know, this actually isn't such a WTF. By issuing a reference to itself, inner non-static classes can access the outer class or in java anonymous (handlers) class. Such as when you need to issue a dialog from a action listener on a button. How do you get a reference to the main dialog?
You can initialize a self reference as a class member variable.
JFrame self = this;
Then in the anonymous action listener you can use that in JOptionPane.showMessageDialog to display the dialog for the correct parent.
Perhaps something similar(a C++ version) occurred and the code was removed later which is why there is no other evidence?
Addendum (2007-09-13 00:43): Huh, been informed by a co-worker that MyOuterClass.this works too. Well, you learn something new everyday.
Admin
Forgetting whether the language uses 'this' or 'self' still isn't an excuse in this case because they still dereferenced 'this' to get to self anyway.
Admin
Admin
Would this(self) confuse the garbage collector? Reference count never goes to zero so the object never gets garbage collected.
Admin
What about: delete first post when number of posts = 1?
Admin
Any half-decent garbage collector should handle circular references without problems. A GC doesn't keep reference counts, but discovers reachable objects instead. If you can't reach something from globals, or locals currently on the stack, it can be reaped, no matter how complicated links it has to other objects (or itself, for that matter).
Admin
Hopefuly they also remembered to do #define begin { #define end } #define == eq just to make things easier
Admin
Admin
Admin
Ah, yes, very clever. Except that since self isn't defined as static, non-static methods won't be able to access it either.
The only thing I can think of (if the original WTF was indeed in C++, as depicted in the submission), is this might have something to do with virtual inheritance. Either he isn't using it but should be... or maybe is using it and needed to work around some side-effect... been too long since I've thought about virtual inheritance to be sure.
And BTW, last I knew (I've been out of the C++ loop for a while now), there was no GC in C++; so I doubt it's anything to do with that.
Admin
Ah, yes, very clever. Except that since self isn't defined as static, non-static methods won't be able to access it either.
The only thing I can think of (if the original WTF was indeed in C++, as depicted in the submission), is this might have something to do with virtual inheritance. Either he isn't using it but should be... or maybe is using it and needed to work around some side-effect... been too long since I've thought about virtual inheritance to be sure.
And BTW, last I knew (I've been out of the C++ loop for a while now), there was no GC in C++; so I doubt it's anything to do with that.
Admin
Potential solution: What if the deinitializer is something like this:
fnCRTLibDeinitialize(CRTLib &*pointerref) { blah blah; pointerref = NULL; }
Seen code like that - perhaps that's the case.
Admin
C++ is fun.
Admin
Two problems I keep seeing in these comments:
If "it's not a WTF because it's valid code because of this and this", it's a WTF because they did something so strange without documenting why.
If they really couldn't remember whether to use self or this: #define self this
Don't you mean: (me.myself & i).whatever();?
Admin
I'm 100% sure this was a Delphi programmer trying to write C++... our company is currently migrating from Delphi to C#, and one of the more "experienced" programmers decided to use this exact same trick to "help with the transition".
Thankfully I caught this behavior before everyone else started copying him; needless to say, he uses "this" nowadays.
On an entirely different topic, Borland should burn in hell for creating the monstrosity that is Object Pascal. It makes me sick just reading it.
Admin
Just Avoid Vain Annotations.
Admin
Remember, the guy who designed Delphi (Object Pascal) is the same guy Microsoft hired to design C#.
Admin
I actually had to do this once, except it wasn't a bare pointer. It went something like this:
Of course, the reason for this was the memory management. One couldn't pass the this pointer because that would initialize a new SmartPointer class resulting in multiple deletes. So, at least it makes sense, I suppose. Unlike the OP.
Admin
I don't know if this was posted but ummm #define self this ??
Admin
If he is trying to use self instead of this because he moved to a new language then it's excusable . The real wtf is this->self, what kind of moron is this?
Nice suicidal LOL . You don't want to kill yourself but you ask yourself to kill the self of yourself which is yourself's self. NO, it's actually yourself's self's self that kill you or the self of yourself by the command of yourself but not you...
Stop here, this self-reflecting thing is getting me crazy.
captcha: Yummy
Admin
Admin
Admin
I learnd programming in Oberon, a language which does not support constructors. So a way to work around the issue is to write an 'init' method which functions as a constructor. I used to create a pointer-member which pointed to the object, exactly like this example. This pointer was set in the init-method. Another method which every class had was something like: boolean isInit(){ return (this.self == this);}. Every method begun with: assert isInit()
Then I learnd c++ and loved it's constructors!
Admin