传递参数1从指针目标类型中丢弃限定符

前端之家收集整理的这篇文章主要介绍了传递参数1从指针目标类型中丢弃限定符前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的主要功能如下:
int main(int argc,char const *argv[])
{
    huffenc(argv[1]);
    return 0;
}

编译器返回警告:

huffenc.c:76:warning:传递’huffenc’的参数1从指针目标类型中丢弃限定符

为了参考,huffenc需要一个char *输入,并且该函数被执行,样例输入通过./huffenc无意义的“无意义”

这个警告是什么意思?

解决方法

这意味着你将一个const参数传递给一个使用非const参数的函数,这是因为明显的原因可能是坏的.

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.

猜你在找的C&C++相关文章