On Fri, 05 Mar 2004 19:13:35 GMT, Nick Landsberg <>
wrote:
>
>
>Dennis Allison wrote:
>
>> Which C libraries (current and historical) interpret a null pointer as
>> a pointer to a null (that is, empty) string?
>
>There was at least one implementation (pre C-89), which
>took great pains into putting 0x0 at location zero
>in the data segment.
>
>Thus, the NULL pointer (on that implemenation a zero)
>would always point to a location with the contents '\0'
>for a char *, and all zero bits for other pointers to
>that location.
>
>Needless to say, things broke in myriad ways when
>code was ported to another implementation.
And even /that/ is more to the tune of "the platform tries to minimize the
potential damage in the case when a C program (user code or lib function)
mistakenly treats a null pointer as if it were a valid pointer to
something".
I get the feeling the OP was asking if there are/were any string-handling
libraries that always check for a special-case of 0 when handed a char *,
and do some reasonable thing in that case.
I don't know, but if there were then that would have to be considered some
sort of non-standard extension, and it might even be offensive to folks
using the string lib functions because it implies extra special-case
overhead that proper use of those pointers would have rendered unnecessary.
Anyway, as a postscript to Nick's remarks, I'm compelled to give out kudos
to the early MSVC team for establishing what I think was an excellent
little "hack" in their runtime system in debug mode: They place a magic
value at location zero, and after program execution check to see if it has
changed. If so, a nice diagnostic ("NULL pointer assignment...") is
emitted. This has probably saved me countless hours of head-scratching over
runtime meltdowns...
-leor
Leor Zolman
BD Software
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