I have a C++ application developed with Visual Studio 2010. I have a static method, which is called to decode messages received via serial hardware.
When I use the "Release" configuration, the compiler somehow optimizes the method in a strange way and the method doesn't work as expected. When I use the "Debug" configuration, everything is fine.
Here's the method:
std::vector<BYTE> CMsg::DecodeMsg(std::vector<BYTE> & msg)
{
std::vector<BYTE> asciiDecoded;
for (size_t i = 0; i < msg.size() - 1; i++)
{
auto val2 = BaseUtils::hex2Ascii(msg.at(i++), msg.at(i));
asciiDecoded.push_back(val2);
}
return asciiDecoded;
}
I think there is something messed up with the i-variable caused by some optimizations (I use /O2) in Release configuration.