pointer = 0 same as pointer = null?

Started by
23 comments, last by vbisme 22 years, 2 months ago
thats where name decoration is useful JonStelly

all my variables are prefixed with their scope and type... it makes it soooo much easier to track them that way.

e.g.
- g_intFred would mean Fred is a global integer
- m_dblBrainFunctionLeftAfterBigParty would be a member variable of a class (and obviously a double)
- l_ptrSomeObject would be a pointer to whatever, and be local within a function

Some may call this approach hideous and hard to read, but once you get used to a style like this, it is actually much easier (no going off to look up the definition). Plus, if you work in a team environment, it saves a lot of pain (the hard part is agreeing on a prefix format )

Don't get me wrong though... this combined with using NULL will make your code all the more readable... NULL just makes more sense than 0 in the context of pointers.


[edit]
As an aside, calling delete in a destructor is indeed very pointless... and if i am not mistaken, will create an infinite loop (calling delete invokes the destructor )

Edited by - Bad Monkey on February 7, 2002 9:32:24 PM
Advertisement
That''s right, Tjoppen''s code will execute infinitely. In fact the line "this = NULL" will never be executed, because the destructor will be called on the delete command that comes before it.

~CGameProgrammer( );

~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
You''re right, variable naming is important. I use my own twisted form of Hungarian, but I guess there''s no such thing as ''too easy to read''. So pile on the simplicity.
how about........

virtual void func() = NULL;

!!!
Well that's a tough call. This is starting to sound like one of those 'you make the call' commercials from decades past.

Anyhow... on the one hand, I don't think of an abstract class's virtual function declarations as declaring a null pointer for the function, since you can't instantiate an instance of an abstract class directly, it just means you'll have to implement the function elsewhere.

But on the other hand, I don't think NULL makes the code any more difficult to read, other than the fact that most people use the '= 0' syntax so it's what they expect.

Edited by - JonStelly on February 8, 2002 3:38:54 AM

This topic is closed to new replies.

Advertisement