Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expression must have pointer-to-object type

Tags:

c++

cuda

I have the following code in CUDA

__global__ void matvec(int *MAT, int *VEC, int *SOL)
{
   int bx = blockIdx.x;
   int tx = threadIdx.x;
   int i = 32*bx+tx;
   for (int j = 0; j < X; j++){
    SOL[i] = ((MAT[i][j] * VEC[j]) + SOL[i]) % 2;
   }
}

My problem is that in line 6 I have an error. It says that my expression must have a pointer-to-object type.

like image 325
Scabro93 Avatar asked Mar 17 '26 01:03

Scabro93


1 Answers

The reason for the error is that you are treating a pointer as a 2D array. You define MAT as int *MAT, but you access it as MAT[i][j].

Assuming you have correctly allocated MAT, I would change this to MAT[i*X + j]. Alternatively, define MAT as int **MAT, again, assuming you have allocated it correctly.

(BTW, this is not a CUDA problem, it is a simple C syntax error.)

like image 198
harrism Avatar answered Mar 18 '26 13:03

harrism



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!