【发布时间】:2021-01-16 00:52:30
【问题描述】:
这是我写的 C 程序 根据先前的答案,我已将变量名称从 SIZE 更改为 arrSize,但在编译代码时仍然显示错误
行:4 列:17 [错误] 数字常量前应为 ';'、',' 或 ')'
#include<stdio.h>
#include<stdlib.h>
#define arrSize 8 //I'm getting error in this line
void merge(int a[], int temp[], int left, int mid, int right);
void display(int [], int);
void msort(int [], int [], int, int);
void merge_sort(int [], const int);
int main() {
int a[arrSize] = {-1, 2, 9, 1, 7, 2, 5, 0};
int temp[arrSize];
printf("Array before sorting:\n");
display(a, arrSize);
merge_sort(a, arrSize);
printf("Array after sorting:\n");
display(a, arrSize);
return 0;
}
void merge_sort(int a[], int temp[], const int arrSize) {
msort(a, temp, 0, arrSize-1);
}
void display(int a[], const int arrSize) {
int i;
for(i = 0; i < arrSize; i++) {
printf("%d", a[i]);
printf("\n");
}
}
【问题讨论】:
-
请edit您的帖子并添加完整的错误消息,并在需要时指出它对应的代码中的哪一行-实际上,有不止一行错误-请@987654322 @.
-
const int arrSize- 预处理器总是首先运行。它会进行令牌替换,所以它变成了const int 8。这就是为什么存在划分宏和常规标识符的命名约定的原因。 -
void merge_sort(int [], const int);你在向你的编译器“撒谎”参数。当编译器稍后看到merge_sort的实现时,这应该会导致错误消息。
标签: c compiler-errors c-preprocessor preprocessor-directive