delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2013/08/01/04:15:16

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: Thu, 01 Aug 2013 03:57:55 -0400
Organization: Aioe.org NNTP Server
Lines: 82
Message-ID: <op.w04oetou0e5s1z@->
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>
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: 3769
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Wed, 31 Jul 2013 09:45:14 -0400, Stephen J. Turnbull  
<turnbull AT sk DOT tsukuba DOT ac DOT jp> wrote:

> Rod Pemberton writes:
>
>  > > It is not possible to give a consistent specification of what
>  > > happens when NULL is passed to a function,
>
> "Consistent" may be a bad word, [...]

I don't think the use of "consistent" is the issue here.

It was clearly the use of "not possible".  It's entirely
possible to specify something consistent.  I'll do so at
the end of this post.

> but my point is that (pointer to char)
> and (NULL) have very different semantics.

What ...?

Do you understand what a NULL pointer actually is?

For some insight, see these posts:

https://groups.google.com/d/msg/comp.std.c/ez822gwxxYA/Jt94XH7AVacJ
https://groups.google.com/d/msg/comp.lang.c/CWc7ti0NUsc/z2RdZlWzlusJ

> The memory referenced by
> the latter can be neither accessed nor mutated,

Untrue.

A NULL pointer can and does point to accessable memory for most C  
compilers.
However, the C language is not required to make access those memory regions
available via a NULL pointer.

The only requirement for NULL (when implemented as a pointer) is that the
pointer value for it does not correspond to the address of any other  
objects
in the C object space, i.e., no address collision.  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.

> [...] so no computations can be done with it.

That depends on whether a NULL is equivalent to a void pointer or a  
constant.
That depends on the generation of the C specification.

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.

> In order to associate an array of chars with NULL,
> you need to make an arbitrary decision.
>

I don't.

As stated, they ("the authors of the various C specifications") didn't  
specify.

>  > It sure is _possible_.  It just wasn't done.  That's entirely
>  > different than actually *not* being able to specify something.
>
> Of course it's possible to specify "something".

Exactly, it's _possible_ to specify "something".

Unfortunately, that's contrary to your prior statement.

E.g., they could've specified a NULL pointer always points to an emtpy
string of just a null character.  Such a specification is unlikely to
break C, since a NULL pointer just needs to have a unique address.
This would've allowed a NULL pointer to safely function as an empty
character string too.


Rod Pemberton

- Raw text -


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