int main(int argc,char const *argv[]) { huffenc(argv[1]); return 0; }
编译器返回警告:
huffenc.c:76:warning:传递’huffenc’的参数1从指针目标类型中丢弃限定符
为了参考,huffenc需要一个char *输入,并且该函数被执行,样例输入通过./huffenc无意义的“无意义”
这个警告是什么意思?
解决方法
huffenc可能不需要一个非const参数,所以应该使用一个const char *.但是,您对main的定义是非标准的.
C99标准第5.1.2.2.1节(程序启动)规定:
The function called at program startup is named main. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv,though any names may be
used,as they are local to the function in which they are declared):
int main(int argc,char *argv[]) { /* ... */ }
or equivalent;9) or in some other implementation-defined manner.
继续说…
…The parameters argc and argv and the strings pointed to by the argv array shall be modifiable by the program,and retain their last-stored values between program startup and program termination.