Click here to Skip to main content
15,911,890 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: I just saw this beauty today... PinPopular
N a v a n e e t h21-Mar-09 17:15
N a v a n e e t h21-Mar-09 17:15 
GeneralRe: I just saw this beauty today... Pin
Dan Neely23-Mar-09 2:19
Dan Neely23-Mar-09 2:19 
GeneralRe: I just saw this beauty today... Pin
WilliamSauron23-Mar-09 4:32
WilliamSauron23-Mar-09 4:32 
GeneralRe: I just saw this beauty today... Pin
Dan Neely23-Mar-09 5:34
Dan Neely23-Mar-09 5:34 
GeneralRe: I just saw this beauty today... Pin
WilliamSauron23-Mar-09 6:01
WilliamSauron23-Mar-09 6:01 
GeneralRe: I just saw this beauty today... Pin
Dan Neely23-Mar-09 6:41
Dan Neely23-Mar-09 6:41 
GeneralRe: I just saw this beauty today... Pin
Jim Crafton2-Apr-09 10:01
Jim Crafton2-Apr-09 10:01 
GeneralRe: I just saw this beauty today... Pin
N a v a n e e t h23-Mar-09 15:56
N a v a n e e t h23-Mar-09 15:56 
William has already explained it neatly. Here is another example if you are interested.
class Dummy{
public:
    void CheckNull(){
        if(!this)
           std::cout << "This is NULL!";
    }
};

Dummy* dummy = 0;
dummy->CheckNull();
You can see This is NULL message appearing in the above example. Above code is problematic and as per C++ standard, calls on an uninitialized pointer will lead into unexpected results.

dan neely wrote:
C++ lets you set the this object in the parameters instead of always using the object the method is called on?


No. AFAIK, compiler compiles the CheckNull() method like
void Dummy_CheckNull(Dummy* this);
and the Dummy instance we created will be passed to this method. Your code will work fine if you are not using the this. Any operation on this will fail as it is not initialized.

Hope it is clear now!

Smile | :)


GeneralRe: I just saw this beauty today... Pin
TheScientistIsDead30-Apr-09 4:34
TheScientistIsDead30-Apr-09 4:34 
GeneralRe: I just saw this beauty today... Pin
N a v a n e e t h3-May-09 17:10
N a v a n e e t h3-May-09 17:10 
GeneralHow to increment a variable [modified] Pin
Kurdy Malloy19-Mar-09 4:42
Kurdy Malloy19-Mar-09 4:42 
GeneralRe: How to increment a variable Pin
Luc Pattyn19-Mar-09 5:20
sitebuilderLuc Pattyn19-Mar-09 5:20 
GeneralRe: How to increment a variable Pin
harold aptroot19-Mar-09 5:38
harold aptroot19-Mar-09 5:38 
GeneralRe: How to increment a variable Pin
Luc Pattyn19-Mar-09 5:42
sitebuilderLuc Pattyn19-Mar-09 5:42 
GeneralRe: How to increment a variable Pin
harold aptroot19-Mar-09 5:56
harold aptroot19-Mar-09 5:56 
GeneralRe: How to increment a variable Pin
Luc Pattyn19-Mar-09 6:26
sitebuilderLuc Pattyn19-Mar-09 6:26 
GeneralRe: How to increment a variable Pin
DanB198326-Mar-09 3:15
DanB198326-Mar-09 3:15 
GeneralRe: How to increment a variable Pin
OriginalGriff14-Apr-09 6:13
mveOriginalGriff14-Apr-09 6:13 
GeneralRe: How to increment a variable Pin
Robert Surtees19-Mar-09 7:30
Robert Surtees19-Mar-09 7:30 
GeneralRe: How to increment a variable Pin
Luc Pattyn19-Mar-09 7:39
sitebuilderLuc Pattyn19-Mar-09 7:39 
GeneralRe: How to increment a variable Pin
Robert Surtees19-Mar-09 7:49
Robert Surtees19-Mar-09 7:49 
GeneralRe: How to increment a variable Pin
Tom Delany9-Apr-09 12:12
Tom Delany9-Apr-09 12:12 
GeneralRe: How to increment a variable Pin
Robert Surtees9-Apr-09 19:56
Robert Surtees9-Apr-09 19:56 
GeneralRe: How to increment a variable Pin
CurtD19-Mar-09 12:59
CurtD19-Mar-09 12:59 
GeneralRe: How to increment a variable Pin
Luc Pattyn19-Mar-09 13:11
sitebuilderLuc Pattyn19-Mar-09 13:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.