Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Development

Development::Development Forum for development topics and for those interested in EQEMu development. (Not a support forum)

Reply
 
Thread Tools Display Modes
  #1  
Old 06-30-2009, 07:24 PM
Shendare
Dragon
 
Join Date: Apr 2009
Location: California
Posts: 814
Default

According to the assembly generated, my Visual C++ 2008 appears to treat both as unsigned ints.

Different compilers may implement such things in their own way, however.
Reply With Quote
  #2  
Old 06-30-2009, 07:32 PM
KLS
Administrator
 
Join Date: Sep 2006
Posts: 1,348
Default

Depends, MSC++ 32 bit compiler treats long and int essentially the same, however you can't rely on this being the case on other platforms or software configurations.
Reply With Quote
  #3  
Old 06-30-2009, 07:50 PM
Kobaz
Hill Giant
 
Join Date: Nov 2008
Location: Gold Coast, Oz
Posts: 119
Default

So in the following code snippet:

Code:
int a = -1;

unsigned int b = 3000000000; // 3 billion

if ( a > b) { "true" >> cout } else { "false" >> cout };
what comes out in Visual C++?
Reply With Quote
  #4  
Old 06-30-2009, 08:03 PM
Shendare
Dragon
 
Join Date: Apr 2009
Location: California
Posts: 814
Default

My compiler outputs "true" in the presented situation.

Microsoft Visual C++ 2008 Standard on WinXP Pro 32-bit.
Reply With Quote
  #5  
Old 06-30-2009, 08:19 PM
Kobaz
Hill Giant
 
Join Date: Nov 2008
Location: Gold Coast, Oz
Posts: 119
Default

What about:

Code:
int a = -1;

unsigned int b = 3000000000; // 3 billion

if ( long(a) > long(b)) { "true" >> cout } else { "false" >> cout };
?
Reply With Quote
  #6  
Old 06-30-2009, 08:32 PM
Shendare
Dragon
 
Join Date: Apr 2009
Location: California
Posts: 814
Default

Still true. In 32-bit, long is the same as int, so they're both being cast as signed ints at that point, changing b from 3000000000 to -1294967296, which is less than -1.
Reply With Quote
  #7  
Old 06-30-2009, 09:04 PM
Kobaz
Hill Giant
 
Join Date: Nov 2008
Location: Gold Coast, Oz
Posts: 119
Default

Sigh. To an old Smalltalk programmer like me, I have to wonder why C++ is called "Object Oriented". I try to understand the language, but it seems to be quite unintuitive.

I'm struggling to understand the emu code - I keep expecting fundamental data types to "do the right thing, with no surprises". How do people write robust correct code in C++ without going mad?

Thanks for your time, I'll just keep away from the code, as I seem to break things due to my Smalltalkness. Perhaps I'm just too old..... everything got hard after about 1986. And don't get me started on Java....
Reply With Quote
Reply


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

   

All times are GMT -4. The time now is 11:09 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3