Home > Mobile >  Compilation error using vector type in C
Compilation error using vector type in C

Time:10-13

Following is the code:

int add;
vector signed int v_add;
v_add[0] = add;

The error is: error: invalid types 'vector int[int]' for array subscript

Problem stays when I try add = v_add[0];

Please explain the cause of this problem. I am using gnu version 3.3.2

CodePudding user response:

You can't treat AltiVec types like vector signed int as if they are arrays. Use e.g. the vec_ld intrinsic to load values from an array to an AltiVec vector.

CodePudding user response:

The error says that compiler doesn't understand type you are using, in vector signed int v_add; you forgot braces <>, you should try vector<signed int> v_add;

Also, you have another error of going out of bounds, but compiler might not tell you about that. You declared an empty vector, and accessed the first element v_add[0] = add;, but the v_add.size() is 0. Try adding values to vector with v_add.push_back(add); or v_add.resize it beforehand;

Another problem with your code is not initializing the value add before adding it to vector. Uninitialized values store garbage from memory in them.

  • Related