I have a bunch of bitsets<32> as global variables in my program and I want to update them after passing a pointer to one of them to a function.
Here is an example:
#include<bits/stdc++.h>
using namespace std;
bitset<32> zero(0);
bitset<32> ra(0);
bitset<32> sp;
bitset<32> gp;
bitset<32> tp(0);
bitset<32> t0(0);
bitset<32> t1(0);
void LUI(bitset<32>*rd, int imm){
bitset<32> temp(imm);
for(int i=31; i>=12; i--){
*rd[i]=temp[i];
}
for(int i=11; i>=0; i--){
*rd[i]=0;
}
}
How can I update for example t1 through the function LUI() as dereferencing is not working? Here are the errors I get:
error: no match for 'operator*' (operand type is 'std::bitset<32>')
46 | *rd[i]=0;
note: candidate expects 2 arguments, 1 provided
46 | *rd[i]=0;
The function
LUIas is does not make sense. I suppose it is only provided as an example of using the subscript operator with bitsets. Nevertheless you could pass to the function bitsets by reference instead of passing them through pointersAs for your problem then instead of
or
you have to write
or
The problem with your code is that the subscript operator has a higher priority than the dereferencing operator.