Re: Where the code trouble is?
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 27 Aug 2005 09:05:03 +0100
Bryan Donlan wrote:
Walter Roberson wrote:
In article <430f8b55@xxxxxxxxxxxxx>, Bart C <bc@xxxxxxxxxx> wrote:
"Richard Bos" <rlb@xxxxxxxxxxxxxxxxxxxxxx> wrote in message news:430ec081.236466745@xxxxxxxxxxxxxxxxx
Writing through a null pointer is no more defined than writing through a wild pointer.
Maybe, but an error is more or less guaranteed with a null pointer and makes it easy to check for.
I know of at least two architectures in which NULL is all-zero-bits but in which writing at (or near that location, such as a[3] when a is NULL) would NOT result in a trap, because the architectures happen to have memory at that location.
The vast majority of machines in use have NULL as a trap location. Richard's development system likely does so as well. Although *NULL might well not trap, it's in general more likely to, which can help with debugging.
This will not catch all such errors of course, but it doesn't hurt anything, except for causing a tiny (probably imperceptible) performance hit, and may help with debugging.
Agreed.
I would also say that even on systems where writing to *NULL does not trap, it is still likely (but not guaranteed) to give reproduceable results which can be debugged.
For similar reasons on embedded systems I have changed the startup code so that all RAM was initialised to all bits 0. I did not check on the system whether NULL was all bits 0 or whether float or double 0 where all bits 0, but it did meen the software was more predictable and easier to debug when accessing uninitialised data. On another system they initialised all RAM to 0x55 for the similar reason (I used all bits 0 because static variables without an initialiser where *not* set to 0).
IMHO the first stage in trying to debug a problem is always to reproduce it, since if you can't reliably reproduce it you will never know if you have fixed what caused the original bug report or something else that you think might have caused it but did not.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
.
- References:
- Where the code trouble is?
- From: mikelinyoho
- Re: Where the code trouble is?
- From: Bart C
- Re: Where the code trouble is?
- From: Richard Bos
- Re: Where the code trouble is?
- From: Bart C
- Re: Where the code trouble is?
- From: Walter Roberson
- Re: Where the code trouble is?
- From: Bryan Donlan
- Where the code trouble is?
- Prev by Date: Re: How do you read two values returned by a function?
- Next by Date: Re: bit fields ordering
- Previous by thread: Re: Where the code trouble is?
- Next by thread: Re: Where the code trouble is?
- Index(es):
Relevant Pages
|