S Scotty Apr 8, 2010 #1 Hi, If I do a (char)-1 in c++ and c# I get a different result: 'ÿ' and '.' Why is that please ?
P PvdG42 Apr 8, 2010 #2 Scotty said: Hi, If I do a (char)-1 in c++ and c# I get a different result: 'ÿ' and '.' Why is that please ? Click to expand... 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.
Scotty said: Hi, If I do a (char)-1 in c++ and c# I get a different result: 'ÿ' and '.' Why is that please ? Click to expand... 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.
F Family Tree Mike Apr 8, 2010 #3 Scotty said: Hi, If I do a (char)-1 in c++ and c# I get a different result: 'ÿ' and '.' Why is that please ? . Click to expand... 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
Scotty said: Hi, If I do a (char)-1 in c++ and c# I get a different result: 'ÿ' and '.' Why is that please ? . Click to expand... 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
I ib.dangelmeyr Apr 9, 2010 #4 If I do a (char)-1 in c++ and c# I get a different result: 'ÿ' and '.' Why is that please ? Click to expand... 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.
If I do a (char)-1 in c++ and c# I get a different result: 'ÿ' and '.' Why is that please ? Click to expand... 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.