我编写了一个函数getopt()
来从命令行获取选项。当我编译它时,我得到这个警告:
cc1: warnings being treated as errors
csim.c: In function ‘getArg’:
csim.c:157: error: passing argument 2 of ‘getopt’ from incompatible
pointer type /usr/include/getopt.h:152: note: expected ‘char * const*’
but argument is of type ‘const char **’
这是C代码:
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(){
}
int getArg(int argc, char const *argv[], int *verbose, int *ps,
int *pE, int *pb, char *traceFileName){
int arg;
int argCount;
while ((arg = getopt(argc, argv, "vs:E:b:t:")) != -1){
switch (arg){
case 'v':
*verbose = 1;
break;
default:
printf("%s\n", "Illegal command arguments, please input again");
exit(-1);
break;
}
}
if(argCount < 4){
printf("%s\n", "Illegal command arguments, please input again");
exit(-1);
}
return 0;
}