Freigeben über


Do you know your language? This time it's the tiny VB quiz ;-)

Dim x = -2147483648Dim y = Integer.MinValue

Well, the question is as easy as that - what Types are x and y and what's the reason?

Cheers

   Daniel

P.S. Needless to say that you shouldn’t use the VB.NET compiler but the one in your head ;-)

Comments

  • Anonymous
    November 28, 2007
    PingBack from http://msdnrss.thecoderblogs.com/2007/11/29/do-you-know-your-language-this-time-its-the-tiny-vb-quiz/

  • Anonymous
    November 29, 2007
    Integer.MinValue is an (32 bit) integer, that part is easy. The -2147483648 is a long, but I'm not sure why. I've seen this happen before and I think it has to do with the way the scanner produces tokens. The deal is that 32bit two's complement ints are supposed to have a range from -2147483648 to 2147483647 and indeed &H80000000 produces -2147483648 as an integer. So I guess the scanner interprets '-2147483648' as two tokens, the literal '2147483648' (which is a long) and the unary '-' operator.

  • Anonymous
    November 29, 2007
    Henk, Perfect! I salute you! "Integer literals are not signed. As a result, the expression -10 is interpreted as the negation operator applied to the integer literal 10. … The expression -2147483648 is typed as Long instead of Integer, because the literal 2147483648 will not fit inside an Integer type (even though its negative will)." (Paul Vick, “The Visual Basic .NET Programming Language”, page 67). Because Integer.MinValue is stored in the BCL as a literal Int32 (0x80000000) VB is able to use that value directly.   Daniel

  • Anonymous
    November 29, 2007
    Ah. Good to know that's actually documented ;-) -- Henkk