我已经编写了一种方法来解析GPS中的字符串,但出于某种原因,关键线在不使用时会被优化掉-O0.方法代码如下:
bool Gps::ParsePMTK_ACK(PmtkAck_t &dst, uint8_t *buf, int32_t size)
{
// Verify message ID
uint8_t *pCur = buf;
memset(&dst, 0, sizeof(dst));
if (strncmp((char*)pCur, "$PMTK001", 8) != 0) {
return false;
}
pCur = pCur + 8; // <--- This line gets optimized away when not on -O0
// thus causing the pointer to NOT be incremented
if (*pCur != SEPARATOR) {
return false;
}
++pCur; // <--- Not optimized away
if (ProcessInt(dst.cmd, &pCur) != 1) {
return false;
} …Run Code Online (Sandbox Code Playgroud)