pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
930 stars 154 forks source link

Avoid using `long` and prefer using `long long` or explicitly-sized integer types? #2609

Open oddbookworm opened 11 months ago

oddbookworm commented 11 months ago

A thought occurred to me: int doesn't have a specific size. Per the C spec (I'm using this freely available draft of C17 https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf, page 31 in section 6.2.5, subsection 5):

A "plain" int object has the natural size suggested by the architecture of the execution environment (large enough to contain any value in the range INT_MIN to INT_MAX as defined in the header

So, technically, an int could be different for different machines even running the same OS. Theoretically then, we could run into a situation with pygame-ce actually doing different things.

Would this be worth investigating?

ankith26 commented 11 months ago

int is usually 4 bytes except a few really rare/old exceptions, and I'm guessing those rare exceptions would not be able to run python or even SDL. We use int in like a million places and a lot of API out of our control already uses int. In short, I don't think going over the code replacing int with anything else is a good idea.

However, the size of long being either 4 or 8 bytes is a more common issue that occasionally bites us, and when it does we do use something like long long or explicitly sized integer types

ankith26 commented 11 months ago

Actually, we could re-open this issue to investigate long usage. I'm sure there would be some places where different platforms behave differently due to this.

So for those who don't know, windows builds with the MSVC have 32-bit longs even on 64-bit hardware (eww, I know) and generally every other 64-bit platform have 64-bit sized long