Closed ErdlingProductions closed 2 years ago
The function _ReturnThruPtr
is doing exactly that... using a pointer. Unfortunately, with the way you've created this test, you've allowed the data to go out of scope by the time your test needs to use it. This is similar to doing this (which is also invalid C design):
char* getName(void)
{
char* retval = "Bob";
return retval;
}
In the example above, if you call getName()
, it MIGHT work sometimes and it might not... it really depends on if the compiler has chosen to do something else with the stack space that you had Bob
sitting in, because retval
is now out of scope.
The solution here is similar. You can add either a const
in front of byte_test
, add a static
in front of byte_test
, or you can move byte_test
out of the function and make it a module scoped static variable. Any of these will keep the contents in scope and your code will be working again.
Hello Mark, I understand. I added static
and it works, awesome :)
const
however did not work for me.
Thanks a lot for your detailed explanation!
Hello! In order to make tests more readable, I wanted to move setup-
Expect
calls into a sub-function. Those setup-Expect calls make use ofReturnThruPtr
in order to deliver data.Example (this test works):
Now if I move the setup to a separate function, the
ExpectThruPtr
does not provide the data anymore, however compilation does not throw any errors.Is this supposed to work or is there a reason why it doesn't? Thanks a lot in advance!