X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: "Rod Pemberton" Newsgroups: comp.os.msdos.djgpp Subject: Re: _CRT0_FLAG_NULLOK Date: Tue, 06 Aug 2013 07:34:36 -0400 Organization: Aioe.org NNTP Server Lines: 76 Message-ID: References: <21e77579-1a40-4442-8111-fc976fba78fc AT googlegroups DOT com> <3df2f50f-9543-47a7-8e40-a9be82ce5018 AT googlegroups DOT com> <87fvuvny2v DOT fsf AT uwakimon DOT sk DOT tsukuba DOT ac DOT jp> <87ehaeonbp DOT fsf AT uwakimon DOT sk DOT tsukuba DOT ac DOT jp> <201308011247 DOT r71ClEhM008182 AT delorie DOT com> <201308031802 DOT r73I2NAq010284 AT delorie DOT com> NNTP-Posting-Host: CNsg4fVcCsvs3UaOgZtQCw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Complaints-To: abuse AT aioe DOT org User-Agent: Opera Mail/12.16 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Bytes: 4592 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Sat, 03 Aug 2013 14:02:23 -0400, DJ Delorie 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