Here is a statement which I wanted to execute:
memoryPos = (memoryPos - 1) % memoryLen;
Info about variables:
- memoryPos is a long long int variable, containing 0.
- memoryLen is a size_t variable, containing 30000.
Running debugger,
(gdb) p memoryPos
$1 = 0
(gdb) p memoryLen
$2 = 30000
(gdb) p (memoryPos - 1) % memoryLen
$3 = 21615
(gdb) p (0 - 1) % 30000
$4 = -1
So somehow when computed with variables, it returns 21615, but I expected either a -1 or 29999.
What is happening here?