delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/04/03/11:01:42

X-Authentication-Warning: acp3bf.physik.rwth-aachen.de: broeker owned process doing -bs
Date: Mon, 3 Apr 2000 16:39:33 +0200 (MET DST)
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
X-Sender: broeker AT acp3bf
To: djgpp-workers AT delorie DOT com
Subject: Re: restrict
In-Reply-To: <Pine.SUN.3.91.1000403130522.27255B-100000@is>
Message-ID: <Pine.LNX.4.10.10004031621080.2210-100000@acp3bf>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Mon, 3 Apr 2000, Eli Zaretskii wrote:
> On Mon, 3 Apr 2000, Martin Stromberg wrote:

> > > Does the standard actually *require* the prototypes to
> > > include `restrict'?
> > 
> > That's my interpretation.
> 
> Yes, but is there anything in the standard, besides the prototypes it 
> shows, that can back up this interpretation?

The definition of 'restrict' itself, obviously. In the words of the
C99 draft:

       [#2] For two pointer types to be compatible, both  shall  be
       identically   qualified   and  both  shall  be  pointers  to
       compatible types.

I.e.: pointer types differing by the addition of a 'const' or 'restricted'
are incompatible. The same holds for function prototypes with such
incompatible pointer types in them. You already get a complaint from the
compiler if you redeclare any function from the standard C library with
differing 'const'ness of its argument, therefore. Quoting again (6.7.5.3
on function declarators):

       [#11]  For  two  function types to be compatible, both shall
       specify   compatible   return   types.116)    Moreover,  the
       parameter type lists, if both are present,  shall  agree  in
       the  number  of  parameters  and  in  use  of  the  ellipsis
       terminator; corresponding parameters shall  have  compatible
       types.   If one type has a parameter type list and the other

In short: we are not allowed to arbitrarily ignore 'const' and 'restrict'
qualifiers in the standard headers. Looks like we'll have to sit down and
check our libc implementation for 'restrict'-safeness.

> The prototype in the standard is meant to document the function.  

I don't think that's true. It's not just a documentation. It's the one
and only prototype of that function allowed to be there, if I'm not
very much mistaken. After all, a programmer is explicitly allowed to
re-declare standard functions in his source code, following exactly the
form given in the standard document. The library is not allowed to fail
or cause compiler error if he does so.

> Compare this with `const': if string.h says this:
> 
> 	size_t strlen (char *);
> 
> is it in violation of the standard?  I wonder.

It is. A conforming program can include 

	#include <string.h>
	#include <stdlib.h>
	size_t strlen (const char *);

and expect to work, as I read the C99 document.

Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


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