Community
cancel
Showing results for
Did you mean:
Beginner
68 Views

## Error: (pointer to array) may not be used in a subscript operation. How could I solve it?

Hello everybody.

I have a pointer like this:

```float **p = ...;
...
_FUNCITON_```

Then I got error info: ` "p" may not be used in a subscript operation.` when compiling it.

So how could I pass a one-dimensional array like this to mic? any advice and suggestions will be greatly appreciated!

1 Solution
Employee
68 Views

Declarations like float **p; are not supported. However, float *p; is supported. p is an array of float pointers. There is a special syntax for transferring pointer arrays:

__declspec(target(mic)) float *p[4];

int main()
{
p[0] = malloc(4*sizeof(float));
p[1] = malloc(4*sizeof(float));
p[0][0] = 55.0;
p[0][1] = 66.0;
p[0][2] = 77.0;
p[0][3] = 88.0;

#pragma offload target(mic) in(p[0:1] : extent(0:4))
{
printf("p[0][0] = %f\n", p[0][0]);
printf("p[0][1] = %f\n", p[0][1]);
printf("p[0][2] = %f\n", p[0][2]);
printf("p[0][3] = %f\n", p[0][3]);
}
return 0;
}

2 Replies
Employee
69 Views

Declarations like float **p; are not supported. However, float *p; is supported. p is an array of float pointers. There is a special syntax for transferring pointer arrays:

__declspec(target(mic)) float *p[4];

int main()
{
p[0] = malloc(4*sizeof(float));
p[1] = malloc(4*sizeof(float));
p[0][0] = 55.0;
p[0][1] = 66.0;
p[0][2] = 77.0;
p[0][3] = 88.0;

#pragma offload target(mic) in(p[0:1] : extent(0:4))
{
printf("p[0][0] = %f\n", p[0][0]);
printf("p[0][1] = %f\n", p[0][1]);
printf("p[0][2] = %f\n", p[0][2]);
printf("p[0][3] = %f\n", p[0][3]);
}
return 0;
}

Beginner
68 Views

Thank you Rajiv!