PC Review


Reply
Thread Tools Rate Thread

Difference of cast between c++ and c# ?

 
 
Scotty
Guest
Posts: n/a
 
      8th Apr 2010
Hi,

If I do a (char)-1 in c++ and c# I get a different result: 'ÿ' and '.'

Why is that please ?
 
Reply With Quote
 
 
 
 
PvdG42
Guest
Posts: n/a
 
      8th Apr 2010

"Scotty" <(E-Mail Removed)> wrote in message
news:d0dc9d86-b46f-4076-9b40-(E-Mail Removed)...
> Hi,
>
> If I do a (char)-1 in c++ and c# I get a different result: 'ÿ' and '.'
>
> Why is that please ?


What character set defines characters associated with negative numeric
values?

If you cast a defined value, do you get the same result in both languages?

By C++, are you referring to ISO standard or C++/CLI?

Bottom line: different languages provide different responses to illogical
input.


 
Reply With Quote
 
Family Tree Mike
Guest
Posts: n/a
 
      8th Apr 2010


"Scotty" wrote:

> Hi,
>
> If I do a (char)-1 in c++ and c# I get a different result: 'ÿ' and '.'
>
> Why is that please ?
> .
>


First, your code would have been:

char c = unchecked((char) -1);

to avoid a compiler error. That would tell you something is amiss.

As PvdG42 wrote, the behavior is rather ill-defined. In fact, when I run
the code above, I get a question mark for any negative number.

Mike
 
Reply With Quote
 
ib.dangelmeyr@googlemail.com
Guest
Posts: n/a
 
      9th Apr 2010
> If I do a (char)-1 in c++ and c# I get a different result: 'ÿ' and '.'
>
> Why is that please ?


Maybe because 'char' is 8 bits in C++ and 16 bits in C#?
C++: -1 (255) results in (ANSI-Codepage) in 'ÿ'
C#: -1 (65535) results in an illegal Unicode character.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
explicit operator cast --> Specified cast is not valid Peter Microsoft C# .NET 1 24th Aug 2011 09:06 AM
Difference between casting by as and normal cast =?Utf-8?B?UmFlZCBTYXdhbGhh?= Microsoft ASP .NET 2 15th Aug 2005 05:00 PM
charting a difference of 2 columns' w/o adding a difference column =?Utf-8?B?V2Fi?= Microsoft Excel Charting 4 27th Jul 2005 02:37 AM
checking for valid cast before cast is called? =?Utf-8?B?d2dpbGxpbg==?= Microsoft Dot NET Framework 1 27th Jun 2005 10:29 PM
how do i download difference account messages into difference fol. =?Utf-8?B?Ymx1X2VibHVl?= Microsoft Outlook 1 10th Oct 2004 05:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:54 PM.