I am having a hard time understanding this. What is: int gindex (unsignedint PC, int bank, longlong hist, folded_history * ch_i). This looks like a regular variable that you are trying to make into a function call or a forward declaration for a function that you did not show or have not defined.
Any way what is in () is confusing because I have nothing to match it with.
class folded_history
{
public:
unsigned comp{}; // <--- Usually variables are made private.
int CLENGTH{}; // <--- Best to use lower case letters. This implies the variable is defined as a constant.
int OLENGTH{};; // <--- Better names would be helpful. I have no idea what the "O" stands for.
int OUTPOINT{};
folded_history() {}
// <--- You could also write as an overloaded ctor:
//folded_history(int original_length, int compressed_length) : comp(0), OLENGTH(original_length), CLENGTH(compressed_length), OUTPOINT(OLENGTH % CLENGTH) {}
void init(int original_length, int compressed_length)
{
comp = 0;
OLENGTH = original_length;
CLENGTH = compressed_length;
OUTPOINT = OLENGTH % CLENGTH;
}
void update(uint8_t * h, int PT)
{
comp = (comp << 1) ^ h[PT & (HISTBUFFERLENGTH - 1)];
comp ^= h[(PT + OLENGTH) & (HISTBUFFERLENGTH - 1)] << OUTPOINT;
comp ^= (comp >> CLENGTH);
comp = (comp) & ((1 << CLENGTH) - 1);
}
};
Sorry, it is my fault, asking correctly a question is a soft-skill that should I learn :)
How should I correctly initialize gindex in the fourth variable that is folded_history * ch_i?
I mean, for example: the first variable of gindex is unsignedint PC that I know that I should write "10, or 22, and any unsigned integer", but for the folded_history * ch_i, I don't know write what?
typically a pointer is initialized to one of 3 things:
nullptr keyword. this is the same as {} initialize for a pointer. This implies that it will get a variable by new or address of etc later on.
the address of a variable:
folded_history fh;
...
folded_histroy * pfh = & fh;
or a new piece of memory:
folded_history * phf = new folded_history[42];
however, ask yourself why you want a pointer in the first place. Is there a good reason that cannot be solved via a vector or a reference or the like?