RSS/Atom feed Twitter
Site is read-only, email is disabled

#defining the restrict keyword

This discussion is connected to the gegl-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

4 of 5 messages available
Toggle history

Please log in to manage your subscriptions.

28887367.54171221319085541.... 07 Oct 20:29
  #defining the restrict keyword Nicolas Robidoux 13 Sep 17:21
   #defining the restrict keyword Sven Neumann 16 Sep 08:14
    #defining the restrict keyword Nicolas Robidoux 16 Sep 15:11
     #defining the restrict keyword Nicolas Robidoux 16 Sep 17:27
Nicolas Robidoux
2008-09-13 17:21:18 UTC (over 16 years ago)

#defining the restrict keyword

Hello Sven:

Given that the restrict keyword may be defined by default for other compilers than gcc (it is in gcc

http://developer.apple.com/documentation/DeveloperTools/gcc-4.0.1/gcc/Other-Builtins.html

wouldn't the following be better?

#ifndef restrict #ifndef G_GNUC_RESTRICT
#if defined (__GNUC__) && (__GNUC__ >= 4) #define G_GNUC_RESTRICT __restrict__ #else
#define G_GNUC_RESTRICT
#endif
#define restrict G_GNUC_RESTRICT
#endif
#endif

This appears to work in (the not yet patched in svn) yafr.

------

Even better:

It appears that autoconf can take care of this in one fell swoop:

http://www.gnu.org/software/libtool/manual/autoconf/C-Compiler.html

See the Macro: AC_C_RESTRICT section.

Nicolas Robidoux Laurentian University/Universite Laurentienne

Sven Neumann
2008-09-16 08:14:47 UTC (over 16 years ago)

#defining the restrict keyword

Hi,

On Sat, 2008-09-13 at 11:21 -0400, Nicolas Robidoux wrote:

Given that the restrict keyword may be defined by default for other compilers than gcc (it is in gcc

http://developer.apple.com/documentation/DeveloperTools/gcc-4.0.1/gcc/Other-Builtins.html

wouldn't the following be better?

#ifndef restrict #ifndef G_GNUC_RESTRICT
#if defined (__GNUC__) && (__GNUC__ >= 4) #define G_GNUC_RESTRICT __restrict__ #else
#define G_GNUC_RESTRICT
#endif
#define restrict G_GNUC_RESTRICT
#endif
#endif

Well, using plain "restrict" probably only works if C99 is enabled. And if C99 is enabled, then there's no need for this macro. So the easiest solution would certainly be to switch to C99 for GEGL.

Sven

Nicolas Robidoux
2008-09-16 15:11:36 UTC (over 16 years ago)

#defining the restrict keyword

Hello:

Sven Neumann writes: > Hi,
>
> On Sat, 2008-09-13 at 11:21 -0400, Nicolas Robidoux wrote: >
> > Given that the restrict keyword may be defined by default for other compilers than gcc (it is in gcc > >
> > http://developer.apple.com/documentation/DeveloperTools/gcc-4.0.1/gcc/Other-Builtins.html > >
> > wouldn't the following be better? > >
> > #ifndef restrict
> > #ifndef G_GNUC_RESTRICT
> > #if defined (__GNUC__) && (__GNUC__ >= 4) > > #define G_GNUC_RESTRICT __restrict__ > > #else
> > #define G_GNUC_RESTRICT
> > #endif
> > #define restrict G_GNUC_RESTRICT > > #endif
> > #endif
>
> Well, using plain "restrict" probably only works if C99 is enabled. And > if C99 is enabled, then there's no need for this macro. So the easiest > solution would certainly be to switch to C99 for GEGL. >
>
> Sven
>
>

I believe that restrict is understood by gcc UNLESS told not to (for example, with -ansi -pedantic). For example, if I put it in gegl-sampler-yafr.c without otherwise changing the make files, the code compiles no problem (whether gcc does something useful with it is another story).

In any case, the above macro will work with any compiler which does support the restrict keyword in whatever mode it is used (c99 ir not). In addition, it does not rely on B_GNUC_RESTRICT being defined to activate "restrict."

Of course, switching to c99 makes this whole discussion irrelevant.

Nicolas Robidoux Laurentian University/Universite Laurentienne

Nicolas Robidoux
2008-09-16 17:27:21 UTC (over 16 years ago)

#defining the restrict keyword

Ooops!

My last post was wrong:

gcc does not understand restrict by default. c99 needs to be turned on, restrict needs to be defined in terms of gcc extensions, or this needs to be take care of by autoconf.

Apologies,

Nicolas Robidoux Laurentian University/Universite Laurentienne