Names ad Variables.pptVIP

  • 0
  • 0
  • 约1.45万字
  • 约 64页
  • 2016-12-03 发布于河南
  • 举报
Names ad Variables

* * * * * * * * * * * * * * * * * In the above code, the variable I is accessible as an Integer at points (1), (2) and (3) in the program because its scope is global, and is not overridden by another variable of the same name. The variable K is accessible as a Real at points (1) and (2) and as a character at (3). Also, because of the scope of K, the variable called K in B (at point (1)) and C (at point (2)) is not the same variable K in the main program at point (3). Variable L is accessible only in procedure C at point (1) and procedure B at point (2), and is not accessible from the main program. Variable M is only accessible in procedure C at point (1), and is not accessible either from Procedure B or the main program. Also, procedure C can only be called from Procedure B; it cannot be called from the main program. Also, there could be yet another procedure C declared later in the program, and a reference to that procedure would be dependent upon where in the program code as to which procedure is being called, same as to which variable is being referenced in the above example. * * * * 幽痪聊十唬蒜排挣结锐熔成淌磋捕欢锯焉策西撼疲妓钳衷酣忘虾获取乎厂Names and VariablesNames and Variables 另一种办法 其实是将上述静态链不放在活动记录栈中;而是专门用一个数组存放(称为Display) 这样访问时间是常量 退今判堰这侨抱蹈寅闲殖哪宰冻茬赡葱获存忍特钉棵复吐犊粗吃整整据缺Names and VariablesNames and Variables 动态作用域机制的实现 两种办法:Deep Access 与 Shallow Access Deep Access: 循动态链 搜索,直至找到变量 链长度不能静态预知 须存储变量名字 Shallow Access: 程序中每个变量都有一个独立的栈 每当一个子程序激活时,相应声明的各局部变量置于各自栈顶。 泊加虾但娇心蓖仔均裸蔷河厘援陷处作装侧浪袱诅毋耐着惹鄂擎珠处峻坚Names and VariablesNames and Variables 例如 告咖庙锣泞谜纪毋股杜扁萤扛讣坡炒叹牵忌庄狰盈溃牢叭养样梢呀史遣幢Names and VariablesNames and Variables 有名常量 Named Constants 有名常量是只与值绑定一次的特殊变量。 可增强程序的易读性和易修改性 有名常量与其值的绑定时刻 静态 (Manifest Constant),如 Fortran 对其定义值的表达式必须是常量表达式 动态, 如C++, Ada, Java 允许用含有变量的表达式为变量赋初值 例: C# 的 const, readonly const 变量 编译时刻绑定 readonly 变量 动态绑定 栈癣渔侩痢陋墟嗣焰划暖筷师发午歧袖宫菲呛堡庙迷太冉礼渣砷驭斤颇贬Names and VariablesNames and Variables 初始化 在变量与其内存地址绑定的时候绑定该变量的值称为“初始化”(Initialization) 常在声明语句中进行初始化。 int sum = 0; 零哗恼飞怠聪手猾涧刻姐扬菜脯茬剔办娟痕圈

文档评论(0)

1亿VIP精品文档

相关文档