Working with databases, int64 to int conversions

Hey guys, this might be very stupid but i was under the impression that on 64bit machines, the int type is actually int64, but i see that working with databases it always returns int64 for integers which messes up my declarations in structs and all, where i have declared simply as int and i always have to convert in between the two.
Is there any way to avoid this? (i mean beside declaring all my ints as int64 directly)

Is there a particular reason why you don’t want to declare them all as int64?

No particular reason at all, i was under the impression that declaring them as int is enough on 64bit machines, but no biggie in using int64 directly.

Anytime you persist data on disk you need to use either a int32 or int64. Why? because you want it to work on both 32-bit machines and 64-bit machines. So if all your ids are bigint (int64), you must NOT convert them to int. That would be a latent bug.

For instance, if you or the next person who runs it, runs it on a 32-bit arm machine and pulls in a 64-bit identifier larger than the 32-bit bitspace, failure of all types will “randomly” ensue.

3 Likes

This is actually very helpful, thank you for the hint, it totally makes sense.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.