E
E. Robert Tisdale
Mabden said:But I am assured this is not the case! You may NOT use the word "ALL".
Please cite an example of a standard conforming C compiler
that does *not* use all-bits-zero for NULL.
Mabden said:But I am assured this is not the case! You may NOT use the word "ALL".
E. Robert Tisdale said:Please cite an example of a standard conforming C compiler
that does *not* use all-bits-zero for NULL.
CBFalconer said:Any one for the 8086/8 in normal segmented mode. Writing to the
interrupt vector table is considered poor technique.
CBFalconer said:Any one for the 8086/8 in normal segmented mode. Writing to the
interrupt vector table is considered poor technique.
CBFalconer said:Any one for the 8086/8 in normal segmented mode. Writing to the
interrupt vector table is considered poor technique.
Now please cease the trolling.
Keith Thompson said:How would using all-bits-zero for null pointers result in writing to
the interrupt vector table?
Are you saying that code that *accidentally* attempts to write
through a null pointer will clobber the interrupt vector table,
thus messing up the system rather than just crashing the
offending program? (I'm not familiar with the systems in
question.)
Ben Pfaff said:In real mode on an x86, the interrupt table is at the bottom of
physical memory. Real mode has a 1:1 mapping from virtual to
physical addresses, so writing through a null pointer will indeed
modify the interrupt vector table.
It's actually worse than that. The first few interrupts in the
table aren't all that important (e.g. the first one is the
"divide by zero" exception vector), so it's possible that writing
to a null pointer won't even mess up the system *quickly*.
Keith said:So using a non-all-bits-zero value for the null pointer (on the system
in question) is a mechanism for defending the system against buggy
code. Cool.
(Of course, if somebody uses memset() to set a pointer to
all-bits-zero, assuming that it's a null pointer, and then
accidentally writes through it, it's going to clobber the system
anyway. Presumably anyone who would do such a thing won't be allowed
anywhere near the system.)
Keith said:How would using all-bits-zero for null pointers result in writing to
the interrupt vector table? Are you saying that code that
*accidentally* attempts to write through a null pointer will clobber
the interrupt vector table, thus messing up the system rather than
just crashing the offending program? (I'm not familiar with the
systems in question.)
Ben said:Every MS-DOS compiler I used had null pointers as all-bits-zero.
What did yours use, and which compiler was it?
In said:I had assumed that "-W -Wall" enabled some required diagnostics, but
if you say "-ansi -pedantic" suffices, I'll take your word for it.
(Using "-W -Wall" as well is generally a good idea, but that's not
necessarily related to conformance.)
CBFalconer said:I _never_ write through a NULL pointer It might be an
experiment to get Borlands TC from the museum and run it through
some experiments on pure MsDOS. I expect int0 will be affected.
A virtual MsDos on W98 won't do.
Joe Wright said:Tell me why any C implementation would have a null pointer other than
zero? So that writing through NULL might be safer? Nonsense. Writing
through NULL is the ultimate sin. So why?
Joe said:.... snip ...
So, if we need a single pointer value within the domains of unsigned
integers of various widths, we are limited to the lower bound, 0.
This is not a bad choice. Usually 0 is an important address to the
underlying OS and we shouldn't write to it in any case. Reserving
address 0 for our NULL pointer constant is perfect. We are warned
that writing or even reading address zero might cause your house to
burn down, and so we don't do it.
Tell me why any C implementation would have a null pointer other
than zero? So that writing through NULL might be safer? Nonsense.
Writing through NULL is the ultimate sin. So why?
Keith said:.... snip ...
Of course, bug-free programs aren't affected by this -- which is fine
if you only run bug-free programs on your system. (The best way to do
that is to pull the power plug.)
.... snip ...
Many years ago, I worked on a 68K-based system programmed in Pascal
(no C compiler). It used the value 1 for the nil pointer because an
attempt to deference an odd address would cause a trap. (Of course,
Pascal doesn't have all the confusion caused by C's use of a literal 0
to represent a null pointer; it just uses the "nil" keyword.)
CBFalconer said:Keith Thompson wrote: [...]Many years ago, I worked on a 68K-based system programmed in Pascal
(no C compiler). It used the value 1 for the nil pointer because an
attempt to deference an odd address would cause a trap. (Of course,
Pascal doesn't have all the confusion caused by C's use of a literal 0
to represent a null pointer; it just uses the "nil" keyword.)
That was UCSD Pascal, which is not representative.
CBFalconer said:Doesn't work on most laptops.
That was UCSD Pascal, which is not representative.
My doubt is that, since we have placed something valid "HRCW in case
of PowerPC" (take the example of an embedded system, where application
has been linked with kernel ) at location all-bits-zero, so isn't it
possible that null pointer may compare equal (because we have some
valid object
at location all-bits-zero).
This may sound very illogical or absurd to the experts, but
this is the picture that i have in my mind.
My doubt is that, since we have placed something valid "HRCW in case
of PowerPC" (take the example of an embedded system, where application
has been linked with kernel ) at location all-bits-zero, so isn't it
possible that null pointer may compare equal (because we have some
valid object
at location all-bits-zero).
This may sound very illogical or absurd to the experts, but
this is the picture that i have in my mind.
[...]Flash Gordon said:2) If the implementation might place the start of a function at all bits
0 then I believe 1 above applies again because a pointer to a function
has has to be distinct from the null pointer.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.