传递参数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语言中的static关键字 在C语言中,static可以用来修饰局...
浅谈C/C++中的指针和数组(二) 前面已经讨论了指针...
浅谈C/C++中的指针和数组(一)指针是C/C++...
从两个例子分析C语言的声明 在读《C专家编程》一书的第三章时...
C语言文件操作解析(一)在讨论C语言文件操作之前,先了解一下...
C语言文件操作解析(三) 在前面已经讨论了文件打开操作,下面...