# FreeBSD and c99 restrict type-qualifier



## tmw (Jan 14, 2010)

Hello,
I have a question abour c99 restrict type-qualifer. I wrote a simple C program to check restrict qualifer :


```
#include <stdio.h>
#include <stdlib.h>
int main() {
int *restrict restar = (int *) malloc(sizeof(int) * 10);
int *sk = restar;

*(sk + 1) = 5;

printf("%d\n", *(sk + 1));
return 0;
}
```

I compiled this code with -std=c99. 

In my understanding of restrict it should be impossible to access memory points by restart pointer throught sk pointer (am i right?), but it is possible in this little program.

On this web page http://www.freebsd.org/projects/c99/index.html i found information that restrict qualifer is still work in progress but some functions in freebsd 8.0 (for example sigaction) are using this qualifer.

So  my two questions are:
- If i understand restrict type-qualifer correctly?
- Why FreeBSD use this qualifer if it is in "work in progress"?

Best regards


----------



## expl (Jan 14, 2010)

Restrict is not a security feature but rather a way to optimize the code. C99 states that in this situation the result is undefined behavior. What GCC actually does that is entirely another question.


----------



## fonz (Jan 15, 2010)

*Better be careful...*



			
				expl said:
			
		

> What GCC actually does that is entirely another question.


One thing gcc(1) *doesn't* do is warning you when you get it wrong. 

Alphons


----------

