-3

OK here's what I am trying. I have passed an array to a function. And while returning I want to send in only those values which are defined in a array. For example, say I have an array definition of 10, I want to return only 5 values from that array, in the function.

Any suggestions!? Thanks.

Sample Code:

sc_uint<8> *arrayfill(struct){
sc_uint<8> array[10];

array[1] = struct.a;
array[2] = struct.b;
...
if (struct.trigger == false){
  array[10] =0;
}
else 
{
  array[10] = struct.j;
}

return array;
}

So now here is the thing, I want to return only upto 9 values of array when struct.trigger is false, else I am returning all the values of array. And this is where I am unable to find a solution.

Harish
  • 3
  • 3
  • The first five? Five picked at random? Five that meet certain criteria? And please show some code. – Biffen Feb 08 '15 at 09:31
  • @Biffen: Its the five that meet a random criteria..!!! I'll put in a sample code below! – Harish Feb 08 '15 at 10:01

1 Answers1

1

I think you can just use the array reference as the in and out parameters, and extract 5 elements from the in array, and then put it into the out array. Like:

void ExtrctElemnts(const std::vector<int>& in_array, std::vector<int>& out_array){
     for(int i = 0; i < 5; i++){
          out_array.push_back(in_array.at(i));
     }
}

Of course, you can also choose specific elements of the in array.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Siyuan Li
  • 21
  • 2
  • @Yu hao: Thanks for your suggestion, but guess that might be the solution for my answer. Please refer the code above for my problem. – Harish Feb 08 '15 at 10:11