Date: Tue, 28 May 1996 09:48:12 +0200 (IST) From: Eli Zaretskii To: Rikard Thunberg Cc: djgpp AT delorie DOT com Subject: Re: printf("%s",0) - Segmentation fault In-Reply-To: <31A987B6.F1@algonet.se> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Mon, 27 May 1996, Rikard Thunberg wrote: > The following line will produce a "Segmentation fault" -error on some platforms/compilers: > printf("%s",0); > > However, some platforms/compilers will produce a string like "(Null)" or similar. You are obviously dereferencing a null pointer here (when `printf' accesses the ``characters'' pointed to by the 0). Any decent protected-mode environment will blow your program off the water in such cases. If `printf' explicitly checks its arguments before accessing them, it can generate "(Null)", but nothing in the ANSI C stanadrd requires it to do so (AFAIK). > Is it possible to tell the compiler what to do in this situation? This has nothing to do with the compiler, but with the way the library functions are implemented. The error must be detected at runtime, not at compile time (because the arguments to `printf' can be variables rather than constants).