Skip to main content
gamedev.net
🔒 Locked

Odd casting issue?

Started by MARS_999 Mar 4, 2004 at 11:24 PM 4 replies 300+ views
Original Post
MARS_999
MARS_999
Maybe I am high! But I guess I never seen a book talk about it or seen it, but assumed that one could type cast unsigned?
float x = 110.1f;
unsigned char c = ''0'';

c = unsigned char(x);
or
float x = 110.1f;
unsigned char c = ''0'';

c = unsigned int(x);
I get errors on this? Why? Shouldn''t I be able to type cast any primitive type?
sordid
sordid
Are you sure that''s the exact same code? I just checked that with .NET (which is more ANSI anal than VC6) and I have no compiler warnings at all, let alone errors.
MARS_999
MARS_999
quote:
Original post by Anonymous Poster
You need to type..
c = (unsigned int)(x);



Coolbeans AP. That works. Why is that? why do I have to () around the type and the variable I want to typecast? Is this an ANSI compliant standard? for unsigned type casts? Thanks
Zipster
Zipster
It probably isn''t recognizing the full unsigned char type. It sees the char, casts it, and then sees some suspicious looking unsigned type that blows its mind.

At least it sounds cool.
emileej
emileej
"oh a char cast. nice... unsigned?! ahr! wtf! noooo!" gmrblmgllbrr!!! stupid compiler. Yeh I had this problem too once
Emil Johansen- SMMOG AI designerhttp://smmog.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.