Operation on … may be undefined?

前端 未结 3 1362
抹茶落季
抹茶落季 2021-02-02 06:21

I have the following code

FRAME frameArray[5][10]; // Create the array of frames
int trackBufferFull[5] = {0, 0, 0, 0, 0};// Keeps track of how full the buffer f         


        
3条回答
  •  忘掉有多难
    2021-02-02 07:06

    trackTail[nodeNumber-1] = ++trackTail[nodeNumber-1] % 10;
    

    Yep, that's undefined behavior just as the error message says. You're not allowed to modify the same value twice without a sequence point in between. In this case that means you're not allowed to both increment trackTail[nodeNumber-1] using ++ and reassign it using =.

    If you just use + 1 instead of ++, it will work fine.

提交回复
热议问题