我的任务是将C程序更改为x86 asm,这一行令我困惑:
int x; arr[100]
完整计划:
int max = 100;
int val = 0x7a;
int x, arr[100]; /*I have a feeling that it is in fact a typo, and my compiler was just being nice*/
main(){
x = 1;/*I just got an email saying this was an error*/
for (x = 1; x <= max; x++){
arr[x] = val;
}
}
我认为这意味着一个数组,但我不确定。
答案 0 :(得分:1)
在老式C中,默认情况下,变量和函数的输入为int
。这解释了arr
的类型以及为什么main()
没有指定返回类型。
答案 1 :(得分:1)
这是int
的数组。在某些情况下,在C99之前,可以在声明中省略类型,然后假设int
。 (请注意,在示例中声明数组后,您缺少;
。
例如:
const x = 10; // valid in C89, not in C99
auto y = 10; // valid in C89, not in C99
答案 2 :(得分:0)
这看起来像错误的代码:
int max = 100;
int val = 0x7a;
// int x; arr[100] // Syntax error
int x, arr[100]; // Declare x as a scalar int, arr as an array of 100 ints
main() {
// x = 1; // Unnecessary, as the for loop initializes x
// for (x = 1; x <= max; x++) { // Writing to arr[100] is an error
for (x = 0; x < max; x++) { // Loop thru indices of arr[]
arr[x] = val; // Set arr[0..99] to 0x7a
}
}