为什么在 Actionscript 3 中使用超过 2 个参数调用此函数会导致堆栈溢出?
function testFunc(val1:int, val2:int, val3:int):int {
var returnVal:int = 0;
return returnVal;
}
var val:int = testFunc(1, 2, 3);
原因
locals: Main int int int *
4:dup VerifyError: Error #1023: Stack overflow occurred.
function testFunc(val1:int, val2:int, val3:int):int {
var returnVal:int = 0;
return returnVal;
}
var val:int = testFunc(1, 2, 3);
causes
locals: Main int int int *
4:dup VerifyError: Error #1023: Stack overflow occurred.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
本页面讨论类似的堆栈溢出问题。似乎在函数中的某处添加
trace
可以修复它。这是一个已知错误
This page discusses a similar stack overflow issue. It seems adding a
trace
somewhere in the function will fix it.It's a known bug
感谢您指出这一事实。无论如何,这是我所意识到的。
AS3 中的函数定义为
function apply(thisArg:*, argArray:*):*
,即任何用户函数都将映射到 adobe 定义的 Function.apply ,如上所述。我猜这与c中的环境变量类似。第一个参数可用于发送参数数组的长度,后跟数组本身。
所以这基本上意味着,如果你想使用上面的函数调用,你可以定义你的函数,因为
我在谷歌上并没有真正找到任何东西。这让我去了 aobe 的页面本身。不管怎样,很高兴我学到了新东西。
编辑:请查看此处的函数定义:
http://www.adobe.com/livedocs/flash/9.0/ ActionScriptLangRefV3/Function.html
Thank you for pointing this fact out. Anyways here is what I realize.
A function in AS3 is defined as
function apply(thisArg:*, argArray:*):*
i.e any user function will be mapped into adobe defined Function.apply as above. I guess this is something similar to the environment variables in c. The first argument can be used to send the length of the Array of arguments followed by the Array itself.
So this basically means, if you wish to use the above function call you can define your function as
I did not really find anything around Google though. Which lead me to go to aobe's page itself. Anyways glad that I learned something new.
Edit: Please do look over the function definition here :
http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/Function.html
是的,这是一个错误播放器,另一种解决方法是将结果转换为 int,因此编译器生成的指令将不一样:
在第一种情况下:
编译器生成类似的内容:
请注意,生成的代码
和解决方法没有任何问题:
生成的代码是
Yes it's a bug player, another workaround will be to cast your result to int, so the instruction generated by the compiler will not be the same:
in the first case:
the compiler generate something like that:
Note that there is nothing wrong with the code generated
and for the workaround:
the code generated is