Mail Archives: djgpp-workers/2003/02/03/07:35:27

Sender: rich AT phekda DOT freeserve DOT co DOT uk
Message-ID: <>
Date: Mon, 03 Feb 2003 12:24:20 +0000
From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.23 i586)
X-Accept-Language: de,fr
MIME-Version: 1.0
To: djgpp-workers AT delorie DOT com
Subject: Re: restrict
References: <200302030730 DOT IAA16240 AT lws256 DOT lu DOT erisoft DOT se>
Reply-To: djgpp-workers AT delorie DOT com


Martin Stromberg wrote:
> Richard said:
> > ams AT ludd DOT luth DOT se wrote:
> > > We have a problem. gcc only recognise "restrict" if "-std=c99" is
> > > given on the command line.
> >
> > Perhaps we should add that flag to gcc.opt?
> Well, we can't unless we want to rule out compiling libc with gcc
> 2.95.3. (I don't.)

It won't compile with -std=c99 and gcc 3.2.1 either (probably any 3.x)! We'd
probably need to enable GNU extensions: -std=gnu99. We can't build libc with
__STRICT_ANSI__ defined, so that rules out using -std=c<number>.

> However, meanwhile I've wondering if having a libc compiled with
> restrict and using headers without restrict or vice versa can be
> problem?

Scenario that I think you are thinking of: library compiled with gcc 3.x;
program using library compiled with gcc 2.95.x.

After reading section "Formal definition of restrict" in the C99
standard, I think you are right that may be problems.

A restricted pointer says that an object will be accessed only through that
pointer in a block and not through, say, another pointer.

The example from the C99 standard is:

void f(int n, int * restrict p, int * restrict q)
  while (n-- > 0)
  *p++ = *q++;

void g(void)
  extern int d[100];
  f(50, d + 50, d); // valid
  f(50, d + 1, d); // undefined behavior

We could modify the library to comply with the restricted definitions. But the
problem is with programs using the library. As the C99 standard says:

"The benefit of the restrict qualifiers is that they enable a translator to
make an effective dependence analysis of function f without examining any of
the calls of f in the program. The cost is that the programmer has to examine
all of those calls to ensure that none give undefined behavior."

I guess the restricted library could have code generated for it that assumes
that objects will only be accessed via one pointer. The calling program could
break that assumption, if it it's compiled with a compiler that does not know
about restrict.

Bye, Rich =]

Richard Dawe [ ]

- Raw text -

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