加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

unix – 什么是qore中的函数参数范围?

发布时间:2020-12-15 21:49:23 所属栏目:安全 来源:网络整理
导读:我对qore 0.8.12中的变量范围感到有些困惑.似乎函数参数与全局变量具有相同的范围 – 这是可能的,还是我做错了什么? 3.1.0 kveton@kvela ~$cat zk1.q %new-style%strict-argssub fun(string v){ print("xxxn");}string v = "zzz";3.1.0 kveton@kvela ~$qor
我对qore 0.8.12中的变量范围感到有些困惑.似乎函数参数与全局变量具有相同的范围 – 这是可能的,还是我做错了什么?

3.1.0 kveton@kvela ~$cat zk1.q 
%new-style
%strict-args

sub fun(string v)
{
    print("xxxn");
}

string v = "zzz";
3.1.0 kveton@kvela ~$qore zk1.q 
unhandled QORE System exception thrown in TID 1 at 2017-01-30 08:10:32.612137 Mon +01:00 (CET) at zk1.q:4
PARSE-ERROR: local variable 'v' was already declared in the same block at zk1.q:9

谢谢你的解释……

解决方法

顶级作用域中的局部变量实际上是全局线程局部变量.

看到:

> https://docs.qore.org/current/lang/html/variables.html#local_variables
> https://docs.qore.org/current/lang/html/threading.html#threading_and_variables

这使得无法使用相同的变量名作为参数变量(它是定义的函数,方法或闭包范围内的局部变量).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读