是否可以在C中指定范围?
int x = 5;
void setX(int x) {
(this, self, etc).x = x;
}
Run Code Online (Sandbox Code Playgroud)
我知道不能有一个this或self在C中,因为它不是一个对象.有没有办法做到这一点?
您可以使用extern这样访问全局变量:
int a = 10;
int foo(int a)
{
int b;
{
extern int a;
b = a;
}
//b now contains the value 10
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
122 次 |
| 最近记录: |