Sender: rich AT phekda DOT freeserve DOT co DOT uk Message-ID: <3E3E5F74.D414BB21@phekda.freeserve.co.uk> Date: Mon, 03 Feb 2003 12:24:20 +0000 From: Richard Dawe 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> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com 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. > 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/ ]