u8 / char conversion problems

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
KaylaKaze
Posts: 75
Joined: Wed May 05, 2004 3:25 pm
Location: NC, USA
Contact:

u8 / char conversion problems

Post by KaylaKaze »

Why won't C++ convert between u8 and char like C does? I'm getting errors like crazy here and it's driving me nuts.
Guest

Post by Guest »

C++ does get a bit more anal retentive about some things that could be done in C. However, without source code showing your variable declarations, assignments, and the problem lines in question, its a little hard to even begin to know the source of your specific problem.
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

Simple, u8 is 'unsigned char', while 'char' is signed by default. C++ is much less tolerant when casting between types than C (and that's a good thing!). Use s8 instead of u8 if you want to get rid of the error.
KaylaKaze
Posts: 75
Joined: Wed May 05, 2004 3:25 pm
Location: NC, USA
Contact:

Post by KaylaKaze »

Well, I know how to get rid of the error (and managed to after a lot of messing with it). It's just changing it all that was a pain in the butt, since all the code had already been written and I was just converting it to C++
cheriff
Regular
Posts: 258
Joined: Wed Jun 23, 2004 5:35 pm
Location: Sydney.au

Post by cheriff »

Cant you just cast from signed -> unsigned??

Code: Select all

u8 a = 42;
char b = (char)a;
b = 37;
a = (u8)b;
seems to work for me, and not too mush hassle...
Damn, I need a decent signature!
KaylaKaze
Posts: 75
Joined: Wed May 05, 2004 3:25 pm
Location: NC, USA
Contact:

Post by KaylaKaze »

The first time I tried casting it didn't work. Later, after getting frustrated enough, I tried again and it did. I seem to be having problems like that: code that worked fine yesterday is now all buggy and when I change a setting in my screen class, the gamepad port won't open (even though they're unconnected).
Raizor
Posts: 60
Joined: Sun Jan 18, 2004 12:27 am
Location: out there

Post by Raizor »

karma...
blackdroid
Posts: 564
Joined: Sat Jan 17, 2004 10:22 am
Location: Sweden
Contact:

Post by blackdroid »

Hahaha :) you mean you reap what you sow ? ;)
Kung VU
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Raizor wrote:karma...
...whore!
"He was warned..."
Post Reply