This is the mail archive of the gcc-help@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: Coredump


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

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