It all depends on the type of Xcp_Addr_t
. Your expression is: &measurements[address]
. The type of the expression is convertible to uint32*
. If your return type is an uint32
in disguise, then just remove the &
operator. If your return type is completely different, you are to rethink what you are doing.
So your typedef is:
typedef uint8* Xcp_Addr_t;
as you can see uint8*
(of the return type) and uint32*
(the actually returned value's type) don't match. You can either change the return type or the type of the array measurements
to:
uint8 measurements[32];
Ok, so you want to ensure that XcpApp_ConvertAddress
returns a valid pointer (without going out of bounds). You have two choices:
- assert it
- throw an exception
You can assert it by doing:
assert(address < 32);
return &measurements[address];
in this case the program will fail at runtime if the address passed to the function is incorrect (notice that you have to add #include <cassert>
to use assert
).
Alternatively you can throw an exception:
if (address < 32) throw std::runtime_error("out of bounds");
return &measurements[address];
(notice that you'll need #include <stdexcept>
for std::runtime_error
).