legal-10
来自「用Java实现的编译器。把源代码编译成SPARC汇编程序」· 代码 · 共 70 行
TXT
70 行
class Program{ int x,y; int m1(int x) { //shadows global x as formal int ret; ret=x; x=100; return ret-1; } int m2(int n) { //shadow global by local int x; x=n+1000; return x; } int m3(int n) { //write to global in proc and main x=4; y=n; return y-100; } void main() { int res; x=2; res = m1(x); if (x==2 && res==1) { callout("printf","shadow by formal OK\n"); } else { callout("printf","FAIL: shadow by formal: %d %d\n",x,y); } x=2; res = m2(x); if (x==2 && res==1002) { callout("printf","shadow by local OK\n"); } else { callout("printf","FAIL: shadow by local: %d %d\n",x,y); } x=2; y=3; y = m3(y+100) + (y-50); if (x==4 && y==56) { callout("printf","proc sideeffect OK\n"); } else { callout("printf","FAIL: proc sideeffect in first operand: %d %d\n",x,y); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?