James Kanze wrote in message...
On Jun 21, 8:51 am, "BobR" wrote:
/* """ quote ( said:
The 0 (zero) is one keypress, the NULL is five (if you count the shift-key).
[see the def below] It 'returns' a zero, so, why not just hit the '0' key?
int *pint( 0 );
vs.
int *pint( NULL );
That is the most stupid reason I've ever heard. You write code
to be read.
""" */ unquote
OH? Then why do so many (mis)use 'typedefs' to reduce typing?
If you are on line 27384 of some code and see "MyVec vec;", is it clear what
it's type/parms are? It's even worse in that case if the typedef is in a
header, now you need to open that header to find what it is.
Yeah, it's a weak argument, but since I use the 0 style, it's clear in my
logic.
I find it hard to believe that some seasoned C++ programmer would have
trouble understanding a zero. <G>
/* """
I'll take the first. Simple, and you don't have to chase down a macro or
documentation to know what it is.
NULL is part of the standard. You don't have to track down any
documentation to know what it is, any more than you do for
"int".
""" */
And we get how many posts a year asking about 'NULL'? :-}
int number( NULL ); // <G> ('newbie' mistake)
// C++, warning: initialization to non-pointer type `int' from NULL
// C ?.
std::cout<<number<<"\n";
// out: 0
[ Dang, now I don't know whether I'm arguing for or against 'NULL'! :-} ]
[snip]
/* """
There's a lot of historical issues floating around. Originally,
C didn't have void*, and 0 was the standard "null pointer
constant". This didn't change when void* was added to the
language, but in the MS-DOS world, the size of a pointer
depended on the compilation model (small, large, etc.), but the
size of an int didn't. This meant that if you passed NULL to a
vararg function, it might not work. (Formally, it was always
undefined behavior anyway, but an amazingly large amount of code
did it, and it worked anyway on a PDP-11.) So some of the
people working on PC's came up with using ((void*)0); the idea
being that the size NULL would automatically adjust to the size
of a pointer. The ISO C standard blessed this usage, along with
allowing implicit conversions both to AND from void* to any
other pointer type. (Most earlier C compilers simply allowed
assigning any int to a pointer.)
About the same time, C++ was gradually developing, but in the
environment where the original C (and not its MS-DOS derivates)
was widespread. In particular, void* was present in C++ before
it appeared in C, and it didn't convert implicitly to other
pointer types. NULL was defined as 0, and C++ introduced
special magic to allow 0 to convert to any pointer type. (Type
checking was much more rigorous in C++, from the very start.)
""" */
I think it was all those little differences in compilers that kept me in
Assembler 'till 2000 ( I used to call 'C' a "glorified librarian".). Again,
not a strong argument. I used 'a386' assembler because it accepted 'MASM'
syntax, but then along came 'NASM', another syntax to deal with. Intel? I
had trouble with their syntax. <G> 65c02, x86, 6800, 68000, mips,
AAAaaaagh!!! Help me, help me!!
So, when I saw that 'C++' had been standardised, I felt it would be worth a
look. Glad I did. If nothing else, the memory management made it worth
while.
It seems older 'C' coders prefer 'NULL'. I had no 'C' hangover, so I prefer
zero. <G> ( ...but then, I avoid pointers where I can. References! "int
&blah = nullptr;" == ouch!)
[snip rest of good info] Thanks.
Well, shall we let it go until next month where we get another 'newbie'
question on NULL? :-}