Mabden said:
I'm trying to let it go, but you just keep baiting me...
You persist in making inaccurate statements. Nobody is baiting you;
we're only interested in accuracy.
BTW, Michael Wojcik and Chris Torek have answered several of your
questions; I've read their responses and I believe they're entirely
accurate.
I just haven't stated my point correctly using lawyer-like, perfect
semantics.
Now Keith, I was enjoying the fact that you didn't start assuming
ignorance on my part because you don't agree with my opinion, but
you are skating really close to the line here.
I know all about zero, pointers, etc. My opinion about location zero
is not due to any ignorance in programming C - although I have
freely admitted I do not own a copy of any "Standards" documents
other than K&R and K&R2.
You could if you wanted to. Visit
<
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/>
and you can get a copy of the latest public draft of the C99 standard
in PDF, Postscript, or plain text. The actual standard differs in
some areas, but I don't believe there are any differences relevant to
the current discussion.
Or you could pay $18 or so for a copy of the actual standard, but
that's not necessary for the current discussion.
In the above quoted paragraph where I wrote that "it's easy to assume
that you share the more common misconception and aren't expressing it
very well", I was not accusing you of expressing yourself unclearly.
I was trying to explain why, due to (what I see as) the unusual nature
of your misconception, a lot of us might have assumed that you're
expressing yourself unclearly.
My strong opinion is that, on this particular point, I'm right and
you're wrong, and that my opinion is based on better sources of
information than yours. I'm not implying that you're a generally
ignorant person, only that you happen to be ignorant on this
particular point. It's nothing personal. Let's both continue working
to keep it that way.
[...]
Even if I am wrong-headed, isn't it still true that location zero cannot be
written to or read from on YOUR machine. I assume you write C programs, so
just do it and tell me I'm wrong!
All my critics, please just write a simple program to read from location
zero in memory. I you can do it, post what you find there.
That's simple, isn't it?
Others have done so in this thread. I'm unable to do so myself,
because all the C implementations to which I currently have access
happen to use all-bits-zero to represent null pointers, and happen to
trap on attempts to dereference a null pointer. (I don't work with
embedded systems other than as an end user.)
Note that C doesn't require a trap for *any* pointer deference,
whether it's null, all-bits-zero, deallocated, uninitialized, or
random. Most such dereferences invoke undefined behavior. One of the
infinitely many possible results of undefined behavior is to quietly
fetch a valid value from the specified location.
(BTW, there's a point that I've ignored so far. A null pointer
doesn't necessarily have the same representation for all pointer
types. Not all pointer types even have to have the same
representation; for example, function pointers might be bigger than
data pointers. This isn't critical to the current discussion, and we
can safely restrict the discussion to systems where all data pointers
look alike and have a unique representation for the null pointer.
This restriction still lets us talk about systems where the
representation of a null pointer is not all-bits-zero.)
Christ, you really are a semantics nitpicker. Yes, not "necessarily" at
zero. Do you want this thread to end or are YOU the troll?
We're talking about a fairly subtle point, so precision is
extraordinarily important. We all make mistakes; whining when someone
corrects them is not constructive.
[...]
I am saying it *should not be* a valid address. IN MY OPINION. I am
not saying that any machine or any compiler or any standard does
this. I am stating that this is how *it should be*.
A serious question: if that sentence on page 102 of K&R2 weren't
there, would you still hold this opinion? What if the errata page
were updated to clarify that there's nothing special about an
all-bits-zero address (unless that happens to be the representation of
a null pointer)?
I have a lot of opinions about the way C *should be* (or, more
accurately, about the way it should have been). Many of them directly
contradict the actual language as defined by the standard and
described by various books including K&R2. I try to make it very
clear that these are just my opinions, and they're not about what the
language *is*, merely about what I might like it to be in an ideal
world.
I think you've been saying one (or both) of two things:
(1) The C language actually requires an attempt to read or write to the
all-bits-zero address to fail; or
(2) In your opinion, the C language *should* require an attempt to read
or write to the all-bits-zero address to fail.
I've been unsure about which of these things you're actually saying.
(That may very well be my fault.) Can you clarify, even if you think
you already have?
If your point is (1), my response is that you are mistaken, and that
this is easily documented. If your point is (2), I suppose I can't
say that you're mistaken, but I strongly believe that such a
requirement would be a bad idea; it would add confusion to an already
confusing area of the language with no real benefit that I can think
of. Systems that should trap on references to the all-bits-zero
address already do; systems that don't, probably shouldn't.
I can't, but others have provided concrete examples.
[...]
I'm not sure how you can know that "each platform has a well-defined
unique pointer value that denotes no object (the null
pointer)". What is that value on the Palm OS? What did NeXT use?
On Palm OS, that value is the null pointer. On NeXT, that value is
the null pointer. I don't know how that value is represented, but
it's likely that it's all-bits-zero in both cases.
I should have said "each C implementation" rather than "each
platform". I know that each C implementation has a null pointer value
because the standard requires it.
(Again, I'm glossing over the possibility of different null pointer
values for different pointer types. Strictly speaking, there's a
distinct null pointer value for each pointer type in each C
implementation. Realistically, it's likely to have the same
representation for void* and all object pointer types for almost all
implementations, even those where a null pointer is something other
than all-bits-zero, but I wouldn't be astonished if there were
counterexamples.)
I assume that is sarcasm? I would LOVE to know what the R thinks, if
you can do that. I suspect it was a joke, and the rest of use
emoticons to make that clear, so a ;-) would have been appropriate.
No, I'm completely serious. Why do you assume that I'm being
sarcastic?