I'm experiencing an odd error. I'm attempting to pass a vector (by reference) to a routine. The vector contains 8 elements, but the called routine receives an empty vector (as evinced by the _M_start and _M_finish addresses being the same). Since I'm passing by reference, it's not invoking the copy constructor (right?), so that can't be the problem.
When I step into the routine, the debugger first puts me into some system code that checks the range on the vector. Using the debugger, I looked at the start and end addresses, and they're the same (indicative of an empty vector). From the calling routine, start and end differ by 0x20, which is correct for a vector of 8 elements.
Also, the program immediately throws a range error when I try to execute the called routine.
Another data point: I discovered that the addresses for the vector in the call not only point to a null vector, but they also point to the starting address of the data in the calling object, ie, the address of cells.
In other words, in the DemodNyq object, the data is stored: cells, inpBuffer, coeffBuffer, which makes sense, since that's how they're ordered in the class definition.
BUT:
The starting address of the first argument received by DemodNyqCell::cycle is that off cells, NOT inpBuffer.
Could be anything. Debugger malfunction, a misinterpretation, undefined behavior... hard to say without seeing all the relevant code.
I suggest adding various asserts where it makes sense, such as assert(!inpBuffer.empty()); both before the call and inside the function and possibly printing vector sizes and line numbers at various places.
I've never used asserts, but I just looked at the reference page on them. I can't put any inside the function, because the function never gets called: the system intercepts it when it range-checks the vector.
I'll put some stuff ahead of the function call and report back.
EDIT:
Nothing new revealed by the asserts or telltales. The program also bombs when running in non-debug mode, so I don't think I can blame the debugger.
Am I formatting my call correctly? I don't have a lot of experience passing vectors as parameters. Should I be passing something like inpBuffer::begin()?
It sounds a lot like you are looking at the range check in the 'at(int)' function of std::vector, not anything to do with cycle(). My guess is the error is being generated because there is no DemodNyqCell object at cells[i], although we can't see how cells is being populated, nor what 'i' is.
Well, you said that a range exception was thrown, which could only have come from at().
However, an assertion before the call should have failed if the vector were empty, revealing the problem.
You're right, Athar. When you suggested using the asserts, I thought you were referring to using it on the parameters of the call, not the object of the call itself. Oh, well, live and learn.