www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/01/10/18:01:07

From: kagel AT quasar DOT bloomberg DOT com
Date: Wed, 10 Jan 1996 17:44:13 -0500
To: dunder AT nyongwa DOT montreal DOT qc DOT ca
Cc: djgpp AT delorie DOT com
Subject: Re: (none)
Reply-To: kagel AT quasar DOT bloomberg DOT com

   Date: Wed, 10 Jan 1996 14:53:28 -0500 (EST)
   From: dunder <dunder AT nyongwa DOT montreal DOT qc DOT ca>



   > >Segment violation in pointer 0x00000000 at d8:de81
   > > 
   > >It works fine compiled with TC... Is this error sent by a particular bug 
   > >en DJGPP or by some 'TC supported' functions or syntax that GCC handles 
   > >badly? Thanx
   > 
   > You're looking for a bug in the wrong place.  The bug isn't in djgpp,
   > the bug is in your program.  At some point in your program you are
   > dereferencing a NULL pointer.  Turbo C didn't catch the bug because
   > there is no memory protection in real mode.  Turbo C will let you smash
   > the interrupt table with reckless abandon.
   > 
   > The easiest way to find the bug is to use the debugger.  It should be
   > able to tell you where the error happened.
   > 
   > Eric

   Well actually I doubt i'd trash the interrupt table since we don't assing
   anything to it at the beginning, therefor, I guess, it points to *nowhere*
   or *anywhere*. The problem we found (after hours of debugging!) is that  
   TC handles NULL pointers by returning a NULL value when comparing
   pointers (ie if(my_pointer) my_pointer[x] = z;) that is, if my pointer is
   initialised, give it a value. Else initialize it. Anyway we remade all 
   the program remodeling the pointer uses and now it works fine with TC and
   GCC! (actually much better in GCC ;) ) Thanx all!
   Hmm btw, how can we test if a pointer is NULL?!


Just as you did, ie:

	if (!my_pointer)
		my_pointer = (my_struct_t *)malloc( sizeof (my_struct_t) ); 

Or BETTER CODE but equivalent:

	if (my_pointer == (my_struct_t *)NULL)
		...

-- 
Art S. Kagel, kagel AT quasar DOT bloomberg DOT com

A proverb is no proverb to you 'till life has illustrated it.  -- John Keats

- Raw text -


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