WTF??!! NULL is not defined in MSVC60??!!

Started by
106 comments, last by null_pointer 19 years, 8 months ago
Quote:Simple, clean, unambiguous.

Correction: overcomplicated, clean, and potentially ambiguous.

1. Overcomplicated. In C++ you use 0. If you feel an irrational need to use the word NULL instead of the numeric constant zero, you just # define NULL 0 or include one of the standard headers that is supposed to do that for you. Defining a template class to emulate the numeric constant zero is ridiculous.

2. Clean. For what its worth, you did a good job formatting it, so I'll give it a 8.5. Technically, you should have used T for TYPE since it's shorter and just as obvious since it is well known.

3. Potentially ambiguous. You unnecessarily introduced several additional names into whatever namespace you would define this class and its instance, and when other people attempt to define their own versions of "null", you have created the potential for naming conflicts. No one will get such conflicts using 0 or the standard NULL macro.

However, it is interesting since I never would have thought of it and nostalgic since it brings to mind an old topic.
Advertisement
Quote:Original post by KulSeran
Then why is there the line:

#define NULL ((void *)0)

in windows.h?


It's in windef.h which is included by windows.h
Hi,

Quote:Original post by null_pointer
2. Clean. For what its worth, you did a good job formatting it, so I'll give it a 8.5. Technically, you should have used T for TYPE since it's shorter and just as obvious since it is well known.


LOL, you didn't take points off for the fact that he used hard tabs for indentation instead of spaces? :P

Seriously, I think the C-style NULL pre-proc symbol works just as well in C++. Don't really see a reason to wrap it in an object of its own. :)

Vovan
Vovan
In C++, the standard requires NULL to be defined if you include the clocale, cstddef, cstdio, cstdlib, cstring, ctime and cwchar headers. If you don't include any of these headers, you have no guarantee that NULL will be defined. (Of course other headers may include these headers themselves, so you may get NULL defined even if you don't include them directly, but you can't rely on such implementation specific behaviour.)
a fun thing to do is after sticking all of your includes in, add the following

#ifdef NULL#undef NULL#endif#define NULL 1
Beer - the love catalystgood ol' homepage
Quote:LOL, you didn't take points off for the fact that he used hard tabs for indentation instead of spaces? :P


I never understood the hatred of hard tabs. Whats wrong with everyone being able to configure their editors to display the indentation however they feel comfortable with? Not to mention it saves just a tiny bit of space.
Hi,

Quote:Original post by Anonymous Poster
I never understood the hatred of hard tabs. Whats wrong with everyone being able to configure their editors to display the indentation however they feel comfortable with? Not to mention it saves just a tiny bit of space.


Well, the space argument is silly. If we want to save space, why don't we just type all the code on one line. Dropping newlines would also save a bit of space. ;)

As far as configuring your editor, well, not all editors can be configured. :) What with people who use notepad, or it's glorified brother - vi?

I guess my own "fear" of tabs comes from my experience in college classes. Every Java project there had to go cleanly through checkstyle, and that program complains about tabs. :)

But really, I was just trying to be funny, hence the :P. ;) I thought it was a little odd that null_pointer commented on the use of TYPE instead of T, and neglected to mention hard tabs instead of spaces. :)

Vovan
Vovan
Quote:I thought it was a little odd that null_pointer commented on the use of TYPE instead of T, and neglected to mention hard tabs instead of spaces. :)


Assigning zero to a pointer is a C++ convention used to express a null pointer, but some of us think that we have to spell out the word N-U-L-L in all of our null pointer expressions for some reason. That's what I was objecting to; not the use of null pointers. :)

As for the tabs, well, the approach is clearly superior to spaces. Some people prefer 2, 3, or 4 spaces. I think that making the source code less flexible just to cope with silly editor deficiencies would be a very bad long term solution.

(And while we're ranting about "infinitely trivial" things, what the heck happened to all the smiley graphics in the posts? Is that only for paying members now? Or mayhap mine actions hath offended the mods?)
The smiley codes were replaced with codes you're less likely to type when you don't mean 'em; see the FAQ for details. We were all fed up with things like std::pair showing up as std:[razz]air.
The forum FAQs are actually being used? [cool]

BTW the [attention] icon appears to be corrupted in Firefox 9.2. It's got a wierd whitish border around it that makes it hard to figure out that it's a yellow exclamation mark. Um...that is what it is, right? [looksaround]

This topic is closed to new replies.

Advertisement