This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Coredump
- To: "Puneet Singhal" <puneet at opussoft dot com>
- Subject: Re: Coredump
- From: Alexandre Oliva <aoliva at redhat dot com>
- Date: 14 Dec 2000 14:12:29 -0200
- Cc: "Gcchelp" <gcc-help at gcc dot gnu dot org>
- Organization: GCC Team, Red Hat
- References: <NEBBJEIPELDNPPCBOLOPGENNCAAA.puneet@opussoft.com>
On Dec 14, 2000, "Puneet Singhal" <puneet@opussoft.com> wrote:
> The same code works fine on NCR UNIX
It works fine on all systems. It's just a matter of defining `fine'.
The code invokes undefined behavior, so the run-time library is
entitled to do anything at all. It might have formatted your hard
disk as well :-)
> When we port the same code to Solaris Sparc it gives a core dump why??
Because printf() ends up dereferencing the NULL pointer you passed to
it. It might have checked whether the given pointer was NULL, but
then every single printf() of a string would incur this cost. Why
impose this cost upon everybody, given that NULL isn't a valid string
anyway?
Besides, by having the program crash at that point, you can easily
figure out where the problem is from the stack trace you can get from
the core file, and fix it. If printf just printed some odd string,
you'd have far more trouble figuring out which statement in your
program makes the invalid printf call.
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me