加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 07:50:12 所属栏目:百科 来源:网络整理
导读:我的主要功能如下: int main(int argc,char const *argv[]){ huffenc(argv[1]); return 0;} 编译器返回警告: huffenc.c:76:warning:传递’huffenc’的参数1从指针目标类型中丢弃限定符 为了参考,huffenc需要一个char *输入,并且该函数被执行,样例输入通
我的主要功能如下:
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 de?ned 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-de?ned manner.

继续说…

…The parameters argc and argv and the strings pointed to by the argv array shall be modi?able by the program,and retain their last-stored values between program startup and program termination.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读