Line 77 is the line
trackTail[nodeNumber-1] = ++trackTail[nodeNumber-1] % 10;
You are changing trackTail[nodeNumber-1]
twice between sequence points: once through ++
, and once through assignment.
This is undefined behaviour.
The remedy is to rephrase the statement, for example like so:
trackTail[nodeNumber-1] = (trackTail[nodeNumber-1] + 1) % 10;
or like so:
trackTail[nodeNumber-1]++;
trackTail[nodeNumber-1] %= 10;
You're modifying trackTail[nodeNumber - 1]
between sequence points. It's like you're assigning
i = ++i;
which is also undefined behaviour.
Change your code to something like this:
trackTail[nodeNumber - 1] = (trackTail[nodeNumber - 1] + 1) % 10;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With