restrict pointers

B

Bart Vandewoestyne

I'm tryign to make a certain piece of code C89 standard compliant
to make it more portable. I also prefer not to use any
compiler-specific extensions. I came across lines that look like
this:

float * __restrict__ f_Qk = f_Q + sk;

From http://en.wikipedia.org/wiki/Restrict i learn that restrict
pointers are just something you can use to optimize and speedup
your code. But for as far as I understand, the __restrict__
macro is something gcc specific?

To make my code C89 compliant and without any compiler-specific
extensions, can I simply replace the above line by

float *f_Qk = f_Q + sk;

and will this keep the behavior of the original code?

Thanks,
Bart
 
I

Ian Collins

I'm tryign to make a certain piece of code C89 standard compliant
to make it more portable. I also prefer not to use any
compiler-specific extensions. I came across lines that look like
this:

float * __restrict__ f_Qk = f_Q + sk;

From http://en.wikipedia.org/wiki/Restrict i learn that restrict
pointers are just something you can use to optimize and speedup
your code. But for as far as I understand, the __restrict__
macro is something gcc specific?

To make my code C89 compliant and without any compiler-specific
extensions, can I simply replace the above line by

float *f_Qk = f_Q + sk;

and will this keep the behavior of the original code?

They are (in the form presented), a compiler specific extension. You
might be better asking on one of the gcc lists.
 
U

Uno

Ian said:
They are (in the form presented), a compiler specific extension. You
might be better asking on one of the gcc lists.

Ohmiheck, Ian, did you have to quote everything to reach the conclusion
that it was compiler specific or way out in left field?
 
I

Igmar Palsenberg

I'm tryign to make a certain piece of code C89 standard compliant
to make it more portable. I also prefer not to use any
compiler-specific extensions. I came across lines that look like
this:

float * __restrict__ f_Qk = f_Q + sk;

From http://en.wikipedia.org/wiki/Restrict i learn that restrict
pointers are just something you can use to optimize and speedup
your code. But for as far as I understand, the __restrict__
macro is something gcc specific?

restrict is a c99 language thingy. __restrict__ is used in code that is
compiled in non-c99 mode, and is thus a gcc extension.
To make my code C89 compliant and without any compiler-specific
extensions, can I simply replace the above line by

float *f_Qk = f_Q + sk;

and will this keep the behavior of the original code?

Yes. restrict just tells the compiler that you won't alias the pointer.
It allow a compiler to optimise code, and prevent certain loads and
stores from being needed (iow, keep a variable in a register).

Removing a restrict won't affect how code works.



Igmar
 
I

Ian Collins

Ohmiheck, Ian, did you have to quote everything to reach the conclusion
that it was compiler specific or way out in left field?

Yes, because it didn't stress my scroll wheel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top