Mail Archives: djgpp-workers/2003/02/03/07:35:27
Hello.
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?
[snip]
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 6.7.3.1 "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 [ http://www.phekda.freeserve.co.uk/richdawe/ ]
- Raw text -