0

I know the use of anonym function have to be done with parsimony but :

private function getAnonymFct() : Function
{
    return function () : void
    {
        var num : uint = -1;

        if( num < uint.MIN_VALUE )
            trace( "WTF ??" );
        trace( getQualifiedClassName( num ) );
        trace( num );
    }
}

public function Main()
{
    getAnonymFct()();
}

Will trace :

int
WTF ??
-1

Any ideas why my var num magically become an int instead of uint as typed ?

Simon Eyraud
  • 2,445
  • 1
  • 20
  • 22

1 Answers1

1

Type uint is shorthand for unsigned integer, -1 is not a valid unsigned integer, it is a signed integer and is less than uint.MIN_VALUE. I would assume, to avoid an obvious runtime error actionscript has converted num to type int.

In AS both unsigned and signed are stored as 32-bits and -1 in base10 as int would be 11111111111111111111111111111111 in base2, converting that to uint it would be 4294967295 in base 10, which is uint.MAX_VALUE and 10 orders of magnitude different to the original number

CyanAngel
  • 1,240
  • 1
  • 14
  • 28