This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC headers and DJGPP port (OT)
- To: torvalds at transmeta dot com
- Subject: Re: GCC headers and DJGPP port (OT)
- From: Marc Espie <espie at quatramaran dot ens dot fr>
- Date: Sun, 23 Jul 2000 16:12:28 +0200
- Cc: gcc at gcc dot gnu dot org
- Organization: Ecole Normale Superieure (quatramaran)
- References: <200007230426.VAA26089@neosilicon.transmeta.com>
In article <Pine.LNX.4.10.10007222131230.1315-100000@penguin.transmeta.com> you write:
>And C++ made the ANSI-C-approved "((void *)0)" define illegal for some
>reason that I still haven't quite grasped. Gcc used to have the "don't
>complain" extension for some time, and now we've moved to "__null". What
>were the issues, just out of morbid curiosity?
C type system is brain-dead.
C++ type system is complicated, but at least, it offers some safety.
Specifically, conversions that increase knowledge about a pointer are
safe, so that you may safely pass an 'int *' to a function that takes a
'void *'.
The reverse is not true, for obvious reasons: you're recreating information
about a type that you don't have.
So, char *p = malloc(15); is invalid in C++, you must put the cast.
(In fact, you will rather use char *p = new char[15] in C++)
Defining NULL to (void *)0 does not work: char *p = NULL; is then illegal.
...and you want a pointer type for NULL so that you will be able to
distinguish f(0) from f(NULL)...
It's C that is completely broken here.
Historically, void is a C++ invention. I don't know what the guys who brought
void to C were thinking (as in, completely clueless). This is one of the
very few cases where C code is not valid C++ code...
Side-note: C's NULL definition is fuzzy enough that var args functions that
want to use NULL as a delineating, null pointer argument can't. For
portability, the logical null pointer in C, when you are not in a typed
context, is (void *)0.