i’m doing some code now and got some problem using restrict keyword.
typedef int* pt;
int foo(pt a, pt b)
{
... /* stuff */
}
What if I want to make a and b restricted? The code below failed:
typedef int* pt;
int foo(pt restrict a, pt restrict b)
{
... /* stuff */
}
Thanks in advance.
You need a “restricted pointer to integer”
int * restrict pnot a “pointer to restricted integer”restrict int *pso you will need to make another typedef. You can’t “reach inside” the original one.EDIT: While it’s true that you can’t reach inside the typedef and the modifier will always apply at the top level, in this case it turns out that you want the
restrictat the top level. It’s the inverse of what people usually run into withconst:typedef char *char_ptrmeansconst char_ptr(orchar_ptr const, they’re equivalent) both mean “constant pointer to char” not “pointer to constant char” which is what people want. (See also this SO thread: C++ typedef interpretation of const pointers )So in this case I think
typedef int *ptdoes mean thatrestrict ptmeansint * restrict pt. It’s pretty easy to verify because gcc will complain about “invalid use of ‘restrict'” forrestrict int *xbut not forrestrict pt x.