devilution icon indicating copy to clipboard operation
devilution copied to clipboard

Signed char types

Open AJenbo opened this issue 6 years ago • 3 comments

On PowerPC char is defined as unsigned char and on x86 it is signed char, since we know that the source was ported to both architectures we should probably replace char with a more specific type. Looking int the symbol file I found int8 on modern Windows SDK's INT8 is defined as signed char, but in the VC6 WINDEF.H it is simply char, there also doesn't appear to be any other values that define signed char, so either they where explicit about it or had a custom type.

This change will probably get us closer to the original source, but also help out ARM (Android) and other platforms that define char as unsigned.

AJenbo avatar Apr 05 '19 18:04 AJenbo

INT8 sounds like it would be fine for a signed char value as VC6 only builds for x86 where char is signed does it not?

OmniBlade avatar Apr 08 '19 07:04 OmniBlade

good point, they probably used a different compiler with it's own includes so int8 could be signed there, just like it is for modern VC.

AJenbo avatar Apr 08 '19 12:04 AJenbo

For now, we have added -fsigned-char, it may not be supported by all compilers and as mentioned in the documentation this isn't the ideal solution:

https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html

MSVC appears to work differently: https://docs.microsoft.com/en-us/cpp/build/reference/j-default-char-type-is-unsigned?view=vs-2019

One of the reasons is that this isn't ideal it that on some architectures code may be more efficient with signed chars and on others, it's vice versa. So it's best to be explicit in the cases where it matters and not when it doesn't. I have also seen people mention issues with calling conventions but couldn't find any documentation to back this up.

AJenbo avatar May 09 '19 19:05 AJenbo