www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/28/11:04:55

Xref: news2.mv.net comp.os.msdos.djgpp:4294
From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: printf("%s",0) - Segmentation fault
Date: Mon, 27 May 1996 10:36:08 -0700
Organization: Alcyone Systems
Lines: 27
Message-ID: <31A9E808.57252601@alcyone.com>
References: <31A987B6 DOT F1 AT algonet DOT se>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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.
> 
> Is it possible to tell the compiler what to do in this situation?

No, except by trying it or looking at the compiler source.  The ANSI C standard
makes no reference to this behavior, and as such it should be treated as any
other behavior when dealing with null pointers:  namely, you're lucky if you
don't crash.

I fail to see how this knowledge could be useful, since you're doing something
you shouldn't be in the first place.  It's just as easy to check with:

    printf("%s", possibleNullPointer ? possibleNullPointer : "(null)");

-- 
Erik Max Francis &tSftDotIotE && http://www.alcyone.com/max && max AT alcyone DOT com
San Jose, California, U.S.A. && 37 20 07 N 121 53 38 W && the 4th R is respect
H.3`S,3,P,3$S,#$Q,C`Q,3,P,3$S,#$Q,3`Q,3,P,C$Q,#(Q.#`-"C`- && 1love && folasade
Omnia quia sunt, lumina sunt. && Dominion, GIGO, GOOGOL, Omega, Psi, Strategem
"Out from his breast/his soul went to seek/the doom of the just." -- _Beowulf_

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019