This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [Fwd: Re: GCC headers and DJGPP port (OT)]


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


# I personally hate using NULL anywhere in C/C++ code.

Hmm. Personally, I feel the opposite. When reading code, it's useful to see
NULL - especially if it's only used with pointer types - because it makes it
obvious to the reader that the lvalue is a pointer and not an integer.
 
# Perhaps, one use of (void *)0 would be to restrict its comparison or
# assignment to int, char, long, ... types. I don't see this advantage as
# significant or important. To try to stop programmers from writing "int
# i=NULL;" is in the direction of trying to stop car-owners from putting
# sand
# in their gas-tanks.

I don't think it's aim is to specifically *stop* users doing this. As with
cars, if a car owner really wants to put sand in her gas-tank, he will.

However, it *does* improve source code legibility. And in the same way as:

 foo.c:7: warning: passing arg 1 of 'bar' makes pointer from integer without
    cast.

It makes it clear that you're dealing with something that wants a pointer,
and not a numeric type. And when you're hacking someone else's code, being
able to see this stuff quickly and easily is very useful indeed.

Consider:

int bar(int, char *, char *, int, char *, size_t);

And somewhere in the sources:

 r=bar(0, 0, 0, 0, 0, 0);

Without referring to the definition of 'bar', could you say which is the
second char * argument?

Whereas:

 r=bar(0, NULL, NULL, 0, NULL, 0);

Makes it obvious straight away.

My 2c.

- -- 
Mo McKinlay             Chief Software Architect          inter/open Labs
- -------------------------------------------------------------------------
GnuPG Key: pub  1024D/76A275F9 2000-07-22 Mo McKinlay <mmckinlay@gnu.org>





-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.2 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE5ez52RcGgB3aidfkRAlQsAKCeJfrWZIQe5eiB4/7AurZ+esfNlwCg3PdY
TBIx55iL74vI5uD4vdN5IrA=
=YEdn
-----END PGP SIGNATURE-----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]