I am trying to make an illegal access? Is it possible that the bit pattern maybe there in
memory in the vector, but the vector is on the stack and hence out-of-scope by
the time control returns from the call?
uint16_t
ldu1::lcf() const
{
int i;
uint16_t lcf;
printf("\n LCF: ");
for(i=0; i<8; i++) cout << decoded_lcw_vec[i]; // how do you know that decoded_lcw_vec contains 8 entries? where does it come from?
for(i=0; i<8; i++) lcf = decoded_lcw_vec[i];
return lcf;
}
looks very dangerous.
At least change it like so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
uint16_t
ldu1::lcf() const
{
int i;
uint16_t lcf = 0; // Note
printf("\n LCF: ");
for(i=0; i<decoded_lcw_vec.size(); i++)
{
cout << decoded_lcw_vec[i];
lcf <<= 1;
//lcf |= decoded_lcw_vec[decoded_lcw_vec.size() - i - 1]; // most significant bit right
lcf |= decoded_lcw_vec[i]; // most significant bit left
}
return lcf;
}
the values are in the vector. so what you are saying is I should not be able to read only 8 of them at a time? the bits are in order. i know where that data payload is, but i am going to try what you have shown above; and I get a seg fault:
Program terminated with signal 11, Segmentation fault.
#0 0xb2d5e6f4 in ldu1::lcf (this=0x0) at ldu1.cc:136
136 for(i=0; i<decoded_lcw_vec.size(); i++)
(gdb) bt
#0 0xb2d5e6f4 in ldu1::lcf (this=0x0) at ldu1.cc:136
#1 0xae9309b8 in ?? ()
So, no matter how I try to do it, the program seg faults when trying to access the vector, out side of the function where it is filled. That vector should, at least I was under the impression it would, persist until the the class was destroyed. This means what? It has to be i am trying to make illegal access right? How can this be since I declared the vector private in the .h file and the class has not been destructed??
i am putting the type before the name and so the compiler thinks the variable is local to that function. but if i take that type away, even though i declared it private in the .h file, i get this compile time error:
ldu1.cc:343:106: error: no match for call to '(bit_vector {aka std::vector<bool>}) (int [72], int*)'
i have no problem getting the values into the vector. the problem is the type 'bit_vector' in front of the the 'decoded_lcw_vec' . its making that variable local instead of a class variable.
i have no problem getting the values into the vector. the problem is the type 'bit_vector' in front of the the 'decoded_lcw_vec' . its making that variable local instead of a class variable.
I misunderstood, sorry.
If bit_vector decoded_lcw_vec(...) ; is in a function, then the decoded_lcw_vec you're copying to is local to that function.
If decoded_lcw_vec is already declared somewhere else and you want to re-fill it try... std::copy(std::begin(corrected_array), std::end(corrected_array), decoded_lcw_vec.begin());
If I'm misunderstanding again, try posting more code, like where the vector is defined and where you are trying to fill it.
it is declared private in the .h file. but it wont compile like that, i dont understand the error on compile:
ldu1.cc: In member function 'void ldu1::correct_lcw(int*)': ldu1.cc:340:106: error: no match for call to '(bit_vector {aka std::vector<bool>}) (int [72], int*)' –
if i use a raw array instead of a vector the program works perfectly. I am just not understanding why declaring the typedef vector in the header gives a compile error.