Should I convert int16/32 to plain old int type?

I’m porting a 20 odd year old C game to Go and naturally it contain lots of different number types; uint8, int16, uint16, int32, uint32, so I’m having to do a lot of casting to get things compiling. I was wondering if perhaps I should convert them all to int and if not, what those reasons might be.

I don’t think memory will to be a problem, although I’ll likely want to convert them to their original sizes when doing the save games to keep the file size down to just a few hundred KB.

Thanks for your thoughts.

Depending on the source, you might run into side effect, if it is relying on controlled over/underflows. I would change it only on a per variable basis, where I can clearly see the use case - for instance “i in for loop” would be a good candidate for “int”.

Hmm, at the moment I can’t be certain controlled overflows aren’t used, so I’ll take your advice and only change the obvious cases for now. Thanks Klaus!

1 Like

I would pay special attention to the uint32 variables as changing them to int (on a 32-bit system at least) could cause overflow if the value is greater than 2147483647.
The rest would be safe to change to int if memory overflow is the only thing you are worried about.

It turns out there’s quite a few places where this is happening, so for the moment I’m going to play it safe and retain all but the most obvious types.

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