www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/19/02:15:29

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: FOUND DJP BUG.
Date: Fri, 18 Apr 1997 21:56:11 -0700
Organization: Alcyone Systems
Message-ID: <3358506B.49561597@alcyone.com>
References: <3353E3F7 DOT 6369 AT tc DOT umn DOT edu>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
Lines: 31
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Jawed Karim wrote:

> #include <stdio.h>
> 
> void main(void)
> {
>         char *string = NULL;
> 
>         if (*string != NULL)
>                 printf("\n%s\n", string);
> }

What you're doing here is dereferencing a null pointer, which is a Bad
Thing To Do.  If it crashes, it's your fault.  If it doesn't, then it's
still you're fault, but the compiler is not necessarily at fault.

For what you appear to be trying to do, by the way, the correct statement
is 

    if (string != NULL) printf("\n%s\n", string);

Your use of *string means you're dereferencing the pointer, which is null.
Very naughty.

-- 
       Erik Max Francis, &tSftDotIotE / email / max AT alcyone DOT com
                     Alcyone Systems /   web / http://www.alcyone.com/max/
San Jose, California, United States /  icbm / 37 20 07 N  121 53 38 W
                                   \
                      "The future / is right there."
                                 / Bill Moyers

- Raw text -


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