delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2013/08/03/09:30:17

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: "Rod Pemberton" <dont_use_email AT nohavenotit DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: _CRT0_FLAG_NULLOK
Date: Sat, 03 Aug 2013 09:20:23 -0400
Organization: Aioe.org NNTP Server
Lines: 96
Message-ID: <op.w08sn91j0e5s1z@->
References: <21e77579-1a40-4442-8111-fc976fba78fc AT googlegroups DOT com>
<b5o37qFldl9U1 AT mid DOT dfncis DOT de>
<f24e8cd3-83ca-4386-a319-a9adb4d74c68 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> <op.w020sren0e5s1z@->
<87ehaeonbp DOT fsf AT uwakimon DOT sk DOT tsukuba DOT ac DOT jp> <op.w04oetou0e5s1z@->
<201308011247 DOT r71ClEhM008182 AT delorie DOT com>
NNTP-Posting-Host: CNsg4fVcCsvs3UaOgZtQCw.user.speranza.aioe.org
Mime-Version: 1.0
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: 5064
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Thu, 01 Aug 2013 08:47:14 -0400, DJ Delorie <dj AT delorie DOT com> wrote:

>> A NULL pointer can and does point to accessable memory for most C
>> compilers.
>
> It's not the compiler that decides this, it's the operating system.

No, it's the compiler.  The compiler can implement NULL as a low address
or high address or anywhere inbetween, as long as it doesn't have the
same address as any existing C objects.

> Many operating systems do not map the first page of memory, [...]

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.

> [...] so a NULL
> pointer may not point to accessible memory.

True.  It could also point at the start of a ROM etc, which could be
accessible during bootup but not later on.  However, that has no
bearing on the fact that NULL typically "does point to accessible
memory for most C compilers".

>>  Typically, this is pointer or address to memory location zero, but
>> it's not required to be.  It can be *any* value as long as no other
>> C object has that same address.
>
> "An integer constant expression with the value 0, or such an
>  expression cast to type void *, is called a null pointer constant."
>
> So, it's zero now.

This is C language semantics for NULL, not the actual implementation
value for NULL used by the compiler.  I.e., a "0" in the code used as
specified represents NULL, but the NULL may actually be at an
address other than zero.

(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.)

>> If NULL's type is a void pointer, it is (losslessly) converted to a char
>> pointer when passed into a function for a char pointer argument.  I.e.,
>> after the conversion, it functions as a char pointer in the function.
>
>  "A string is a contiguous sequence of characters terminated by and
>   including the first null character."
>
> So there's a difference between "char pointer" and "pointer to a
> string".

True.

Strings are "second class citizens" being implemented as arrays in C.

>  atoi() takes a pointer to a string.

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.

> Not all char pointers are pointers to strings.

True.

(So far, I'm *really* unsure why you're attempting to educate me on the
definition of a C string ...  Was this for the OP?)

> "If a null pointer constant is converted to a pointer type, the
>  resulting pointer, called a null pointer, is guaranteed to compare
>  unequal to a pointer to any object or function."

Exactly.  That was stated by me in the other post and again above.

> Since a pointer to any valid string cannot be equal to the null
> pointer, a null pointer cannot point to a string.

Sorry, you've made a logic error here.  The prior quote of yours only
requires the address used for the NULL to be unequal to any valid object
or function.  You've implicitly defined your own term: "valid string",
as including the hypothetical null string that would be stored at NULL's
address.  The "NULL null string object" would need to be excluded from
your definition of "valid", i.e., be present and useable as a null string,
but not considered to be "valid" since the system created it not the user,
i.e., just like NULL is defined as not valid.


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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019