Re: interpreting a null pointer as an empty (null string)
From: Leor Zolman (leor_at_bdsoft.com)
Date: 03/09/04
- Next message: Clark Cox: "Re: interpreting a null pointer as an empty (null string)"
- Previous message: CBFalconer: "Re: Yet another pointer related problem"
- In reply to: Richard Bos: "Re: interpreting a null pointer as an empty (null string)"
- Next in thread: Clark Cox: "Re: interpreting a null pointer as an empty (null string)"
- Reply: Clark Cox: "Re: interpreting a null pointer as an empty (null string)"
- Reply: Richard Bos: "Re: interpreting a null pointer as an empty (null string)"
- Reply: William L. Bahn: "Re: interpreting a null pointer as an empty (null string)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 09 Mar 2004 14:30:44 GMT
On Tue, 09 Mar 2004 13:30:41 GMT, rlb@hoekstra-uitgeverij.nl (Richard Bos)
wrote:
>Leor Zolman <leor@bdsoft.com> wrote:
>
>> "Among the invalid values for dereferencing a pointer by the unary *
>> operator are a null pointer,..."
>>
>> Sorry for beating a seemingly dead horse, but I'm not seeing how this
>> leaves any wiggle room to make that operation "valid".
>
>You are correct, but I think there's been a miscommunication along this
>thread. To me, and it seems to Keith as well, it looked as if you were
>saying that treating null pointer dereferences as empty string
>references is illegal, for the implementation. This is not true.
No, I was actually saying (and I'm still working on letting myself be
talked out of it) that the discussion shouldn't even /reach/ the point of
asking how the result of such a dereference may be treated, because getting
there requires doing something that has undefined behavior (or, at least,
involves the use of something that has been labeled as "invalid").
Okay, this is good. Perhaps I'm about to get how I went astray. Setting the
Way-back machine to my message dated 3/8 at 8:05pm, here's how I re-entered
the fray:
------------------------------------------------------------------------
>> Those on systems that map memory page zero as an unused, all zeros
>> memory page, typically read only. Thus, you have a null character at
>> memory address 0, which is the usual destination of the null pointer.
>
>Absolutely unportable, implementation-dependent, and
>maybe operating system level dependent.
Looks like this is explicitly disallowed by the Standard, to boot. Section
6.5.3.2, footnote 83, says (in part):
"Among the invalid values for dereferencing a pointer by the unary *
operator are a null pointer, ..."
------------------------------------------------------------------------
I used the words "explicitly disallowed" when citing the footnote about
null pointers being "invalid" as operands of the indirection operator; my
thinking here was that any implementation that actually tries to /look/ at
location zero through a null pointer would therefore be in direct
violation of the standard (and not "just" doing something whose outcome is
implementation-dependent.) Yet everyone here is telling me that platforms
are free to allow such dereferencing...
>
>_You_ are not allowed to dereference a null pointer. Doing so is
>undefined behaviour. This means that, once you _have_ done so, the
>implementation is free to treat it any way it pleases - which includes
>pretending that you'd dereferenced a pointer to an empty string. IOW,
>you're not supposed to rely on this, but the implementation doesn't
>break the Standard if it lets you do so.
So is there actually any difference whatsoever in anybody's mind between
something labeled by the Standard as "undefined behavior" and something
else labeled an "invalid" practice? Let me postulate that the answer is
"no".
And then: Would I be correct in saying that the difference between code
that is "disallowed" and code that is invalid/has undefined behavior is
that being "disallowed" requires the compiler to diagnose it, while
invalid/UB code does /not/ require the compiler to diagnose it, and such
code may have well-defined behavior in the domain of some arbitrary
platform (thus of course being non-portable)?
I feel close, really close... ;-)
Thanks all,
-leor
Leor Zolman
BD Software
leor@bdsoft.com
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
- Next message: Clark Cox: "Re: interpreting a null pointer as an empty (null string)"
- Previous message: CBFalconer: "Re: Yet another pointer related problem"
- In reply to: Richard Bos: "Re: interpreting a null pointer as an empty (null string)"
- Next in thread: Clark Cox: "Re: interpreting a null pointer as an empty (null string)"
- Reply: Clark Cox: "Re: interpreting a null pointer as an empty (null string)"
- Reply: Richard Bos: "Re: interpreting a null pointer as an empty (null string)"
- Reply: William L. Bahn: "Re: interpreting a null pointer as an empty (null string)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|