Date: Thu, 11 Jan 1996 18:54:43 From: "Alaric B. Williams" Reply-To: DJGPP AT abwillms DOT demon DOT co DOT uk To: "Eric J. Korpela"@abwillms.demon.co.uk, dunder AT nyongwa DOT montreal DOT qc DOT ca Cc: djgpp AT delorie DOT com Subject: Re: (none) Lines: 47 In your message dated Wednesday 10, January 1996 you wrote : > > > > >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?! A pointer is NULL if it has the value NULL. It's not like there's two states, NULL and useful, NULL is just an address in memory you're not likely to want to point to. Indeed, you might want to do something with the interrupt table, which is where NULL normally points to in real mode, in which case you'd use a NULL pointer. Just you always know that something like malloc will never return NULL, unless it wants to say something's wrong and that it can't give you a memory block. That is why we have NULL. By rule and convention, NULL is the value 0. To test if a pointer is NULL, use if(!pointer) ... -- Alaric B. Williams (alaric AT abwillms DOT demon DOT co DOT uk) "A man walks into a bar, right, and he goes 'ouch' coz it's an iron bar"