www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/14/15:48:44

From: elric AT wheel DOT dcn DOT davis DOT ca DOT us (Jeffrey Taylor)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: strcmp("anything",NULL) -> error ??
Date: 14 Feb 1997 18:04:00 GMT
Organization: Davis Community Network - Davis, California, USA
Lines: 23
Message-ID: <5e29eg$ea0$1@mark.ucdavis.edu>
References: <5e18hb$tb8 AT www DOT iil DOT intel DOT com>
NNTP-Posting-Host: wheel.dcn.davis.ca.us
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Amit Barak (abarak AT iil DOT intel DOT com) wrote:
: it seems that calling 'strcmp(..)' with one of its arguments equals
: a null pointer causes run-time error (Page fault)
: 
: is this normal behavior (compared to other compilers) ?
: 

It does vary with compiler and OS/CPU.  In ANSI C, it is definitely a
no-no (AKA implementation-dependent behavior :)

Deferencing the NULL pointer is a bad idea.  You can assign it and compare
against it for equality.  That's about it.

Did you mean to compare against the null string ("")?  Even if you don't
get a segment fault, you will get unportable and unpredictable results.
In real mode, large model, low memory is the interrupt vectors and can
change from one run to the next.  In small model, some compilers put the
copyright notice there (easy to identify when you print it).  Others put a
string like <null pointer> there.  Several compilers mak ethe first page
in virtula memory inaccessible to catch attempts to dereference NULL (and
small integers).

Jeff

- Raw text -


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