Windows Vista Forums

Difference of cast between c++ and c# ?
  1. #1


    Scotty Guest

    Difference of cast between c++ and c# ?

    Hi,

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

    Why is that please ?



      My System SpecsSystem Spec

  2. #2


    PvdG42 Guest

    Re: Difference of cast between c++ and c# ?


    "Scotty" <matthieu.sarthou@newsgroup> wrote in message
    news:d0dc9d86-b46f-4076-9b40-f44443198156@newsgroup

    > 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.



      My System SpecsSystem Spec

  3. #3


    Family Tree Mike Guest

    RE: Difference of cast between c++ and c# ?



    "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

      My System SpecsSystem Spec

  4. #4


    ib.dangelmeyr Guest

    Re: Difference of cast between c++ and c# ?

    > 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.

      My System SpecsSystem Spec

Difference of cast between c++ and c# ? problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Type cast Joachim Meyer PowerShell 1 26 Aug 2008
Specified cast is not valid RW .NET General 3 06 Mar 2008
meaning of this cast ? Leo Tohill PowerShell 3 15 Nov 2007
Verizon V-cast software justbob30 Vista General 2 14 Aug 2007
Yellow cast issue... MiKeV Vista music pictures video 1 09 Feb 2007