Why does my uint64 overflow at 2^32-1?

This code:

uint64 derp = 0;
UE_LOG(HelloWorld, Error, TEXT("derp = %i"), derp);
derp = 4294967295;
UE_LOG(HelloWorld, Error, TEXT("derp = %i"), derp);
derp = 4294967296;
UE_LOG(HelloWorld, Error, TEXT("derp = %i"), derp);
derp = 4294967297;
UE_LOG(HelloWorld, Error, TEXT("derp = %i"), derp);

produces this output:

HelloWorld:Error: derp = 0
HelloWorld:Error: derp = -1
HelloWorld:Error: derp = 0
HelloWorld:Error: derp = 1

this is not the behavior I was expecting. What’s going on here?

Replacing %i with %u yields:

HelloWorld:Error: derp = 0
HelloWorld:Error: derp = 4294967295
HelloWorld:Error: derp = 0
HelloWorld:Error: derp = 1

%llu did the trick, though this means I have a problem somewhere else in my code.

Thank you very much!

I think proper formatting is %ld and %lu - what happens in that case?

(EDIT: or even %lld and %llu to be on the safe side).

In code format, because I can’t tell if it’s a upper case i, or a lower case L.

I think proper formatting is %ld and %lu - what happens in that case?

(EDIT: or even %lld and %llu to be on the safe side).

Cheers

it’s a lowercase L, as in “long”: “ld” would be “long decimal” and “lu” is “long unsigned”