Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MARS_999

Odd casting issue?

This topic is 5345 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You need to type..
c = (unsigned int)(x);

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
"oh a char cast. nice... unsigned?! ahr! wtf! noooo!" gmrblmgllbrr!!! stupid compiler. Yeh I had this problem too once

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!