Mail Archives: djgpp/2013/08/06/07:45:12
On Sat, 03 Aug 2013 14:02:23 -0400, DJ Delorie <dj AT delorie DOT com> wrote:
>> A NULL is not required to be mapped to low memory. This is
>> irrelevant. NULL's actual value is not required to be zero, only
>> different.
>
> NULL's actual value is required to be zero, from the program's point
> of view.
>
If it's from the program's point of view, then it's not it's actual
value. It's its semantic representation.
>> (No joke. You can ask even the angry nutjobs on c.l.c and get that
>> correct answer. Please read the two posts which I provided links
>> to. They're by one of the authors of the ANSI C specifications.)
>
> Sure. The physical address of "0" in a virtual memory system is
> rarely itself zero, and some systems use segment/offset or tag/offset
> addressing too.
>
That's only true if paging or MMU is involved. C was implemented
prior to virtual memory on many machines that didn't have it. All
microprocessors started out with physically mapped memory. Neither
the 68K series nor the x86 series had MMUs for a few generations of
each processor. To this day, the mode x86 starts in is physically
mapped, not paged, not segmented, not virtual. DJGPP seems to be
unique in the DOS world for using virtual memory.
The point is on *any* memory system The actual value used for
NULL needn't be zero. It just needs to not collide or compare
equal with the values used for other C objects.
>> True. We were discussing how to make a NULL more useful by
>> preventing atoi() from failing when passed in. One method is for
>> NULL to be not just a "char pointer", but also be "a pointer to a
>> string" - an empty string.
>
> IMHO, making "passing NULL" crash your app is more useful, because
> then the debugger can tell you exactly where you went wrong. Even the
> MCU simulators I write for work have *NULL==crash for debugging.
>
So, I take it you also disagree with the C compiler automatically
initializing unitialized variables. That prevents users from making
coding mistakes too... Shouldn't they clear their variables themselves?
I'll also take it you dislike 'void' and 'void*' since those also
prevent users from coding making certain coding mistakes with pointers.
Wrong assumption? Of course, it is... I seriously can't imagine you
disliking either of those. I.e., I don't see why you'd like the just
mentioned "safety" features of C, but you wouldn't like another change
that would prevent similar novice style coding mistakes...
> IMHO if a pointer points to *anything* that "works", it's
> a bad choice for NULL.
Even if NULL still functions correctly as NULL?
Why would that be an issue?
NULL can still be compared to. It just now functions as an empty
string for functions expecting strings, if they don't explicitly
check for NULL. If they do, it functions as NULL. That can prevent
runaway on a call to strlen(), strcmp(), if the function didn't
explicitly check for NULL. By "runaway", I mean searching for a
null character '\0' when one hasn't been properly placed.
Rod Pemberton
--
"... to secure these rights, governments are instituted among men,
deriving their just powers from the consent of the governed; that
whenever any form of government becomes destructive of these ends,
it is the right of the people to alter or abolish it ..."
-Thomas Jefferson, Declaration of Independence, 1776
- Raw text -