Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 23rd, 2007, 8:35 PM   #1
null_ptr0
11 years old
 
Join Date: Nov 2007
Posts: 79
Rep Power: 1 null_ptr0 is on a distinguished road
Casting signed int to unsigned int?

I know I could use simple C casts (unsigned int uint_fld = (unsigned int) ivar;) but I'm not sure if I should use some of the handy casting functions (unsigned int uint_fld = dynamic_cast<unsigned int>(ivar);). Which should I chose?


sidequestion: I have countlessly just casting something unsigned through
c++ Syntax (Toggle Plain Text)
  1. unsigned char uchar_var = (unsigned) char_var;
, but is this appropriate for c++ programming?
null_ptr0 is offline   Reply With Quote
Old Nov 23rd, 2007, 9:27 PM   #2
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 498
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: Casting signed int to unsigned int?

Most c++ pureists would say that it is NOT appropriate for c++. IMO (for what its worth) I think it depends -- in your example it would be ok, but in more complex situations it would not. If you do use the c-style castings you must make sure you absolutely KNOW what you are doing because the compiler will simply assume you are correct -- no error checking. The compiler will produce warnings or error with c++ casts.
Ancient Dragon is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Correlating an int with a string truBlu C++ 6 Oct 12th, 2007 10:18 AM
Passing int arrays as arguments... Soulstorm C++ 9 Sep 3rd, 2007 8:13 AM
splitting up char and converting to int jokr004 C++ 10 Jul 20th, 2007 4:09 PM
Question regarding Malloc() and Type casting sparda C 6 Sep 29th, 2005 4:12 AM
Storing Negative Numbers in unsigned ints aznluvsmc C 9 Aug 22nd, 2005 10:09 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:41 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC