|
signed char became unsigned ? |
Posted on: 1/21 19:42
#1 |
---|---|---|
Home away from home
![]() ![]() Joined:
2007/9/11 12:31 From Russia
Posts: 6823
|
@All
Have some theoretical question. I do work on some port of a game, which is C++ and which have such a class:
class Door : public Object
Now, in the code of the game, depending on the needs, we have set _direction to be 1 or -1. Like this:
void Door::setDirection(core::vector3df ref)
And when I build it for win32 and when puts prints with %d in relevant parts, it prints 1 or -1 when should. But when I do the same on amigaos4, it prints then 1 and 255 instead of 1 and -1 (i.e. -1 became 255). I.e. exactly the same code line per line. Just 2 binaries, one for aos4 and one for win32. I feel it's something trivial, just can't get what. Does it look like signed char become unsigned? Maybe I need specially specify that this is signed? Or maybe some flag to GCC need to be passed, or it just bad code-practice somewhere? Maybe in win32 pure "char" mean "signed char", but on amigaos4 pure "char" mean "unsigned char" ?:) |
|
|
Re: signed char became unsigned ? |
Posted on: 1/21 20:00
#2 |
---|---|---|
Home away from home
![]() ![]() Joined:
2007/9/11 12:31 From Russia
Posts: 6823
|
Damn right, win32:
$ cat test.cpp
Amigaos4:
2/10.Work:test> cat test.cpp
So seems just different defaults. Strange through why differences have a place at all between platforms in such case. |
|
|
Re: signed char became unsigned ? |
Posted on: 1/21 20:20
#3 |
---|---|---|
Just can't stay away
![]() ![]() Joined:
2006/11/30 11:30 From Finland
Posts: 1799
|
@kas1e
Whether char type defaults to signed or unsigned is and always has been platform dependent. If you require a specific type of char (signed or unsigned) you should specify it in the variable definition. In this case: signed char _direction = -1; |
|
|
Re: signed char became unsigned ? |
Posted on: 1/21 20:44
#4 |
---|---|---|
Quite a regular
![]() ![]() Joined:
2007/2/27 10:47 From Gravity well
Posts: 727
|
There should be a warning in gcc for that. It's *the* cross platform toolchain.
|
|
|
Re: signed char became unsigned ? |
Posted on: 1/21 21:13
#5 |
---|---|---|
Just popping in
![]() ![]() Joined:
2018/3/1 21:08 From italy
Posts: 26
|
These is a gcc compiler option about how to manage chars datatypes.
Maybe on windows defaults are different from others platforms. As suggested you can declare var as signed char and look at debug printf output just to verify. |
|
_________________
Memento audere semper! |
||
|
Re: signed char became unsigned ? |
Posted on: 1/21 22:03
#6 |
---|---|---|
Home away from home
![]() ![]() Joined:
2007/9/11 12:31 From Russia
Posts: 6823
|
@All
As code is written like this, probably it's better to use --fsigned-char GCC option then? Or it may fix this part, but fail then in another... |
|
|
Re: signed char became unsigned ? |
Posted on: 1/21 22:18
#7 |
---|---|---|
Just popping in
![]() ![]() Joined:
2011/7/20 20:01 From In the sticks
Posts: 138
|
@kas1e
-fsigned-char should do it for you in GCC. |
|