传递参数1会从指针目标类型中丢弃限定词 [英] Passing Argument 1 discards qualifiers from pointer target type

查看:94
本文介绍了传递参数1会从指针目标类型中丢弃限定词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主要功能如下:

int main(int argc, char const *argv[])
{
    huffenc(argv[1]);
    return 0;
}

编译器返回警告:

huffenc.c:76: warning: passing argument 1 of ‘huffenc’ discards qualifiers from pointer target type

huffenc作为参考,huffenc接受一个char*输入,然后通过./huffenc senselessness

For reference, huffenc takes a char* input, and the function is executed, with the sample input "senselessness" via ./huffenc senselessness

此警告意味着什么?

推荐答案

这意味着您正在将const参数传递给带有非const参数的函数,由于明显的原因,该函数可能很糟糕.

It means that you're passing a const argument to a function which takes a non-const argument, which is potentially bad for obvious reasons.

huffenc可能不需要非const参数,因此应使用const char*.但是,您对main的定义是非标准的.

huffenc probably doesn't need a non-const argument, so it should take a const char*. However, your definition of main is non-standard.

C99标准第5.1.2.2.1节(程序启动)规定:

The C99 standard Section 5.1.2.2.1 (Program startup) states:

在程序启动时调用的函数称为main.实现声明为否 此功能的原型.它应使用返回类型int定义,且不包含 参数:

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) { /* ... */ }

或带有两个参数(此处称为argc和argv,尽管任何名称都可以是 使用,因为它们对于声明它们的函数是局部的):

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[]) { /* ... */ }

或等效形式; 9)或以其他实现方式定义的方式.

or equivalent;9) or in some other implementation-defined manner.

接着说...

...参数argc和argv以及argv数组指向的字符串 可由程序修改,并在程序之间保留其最后存储的值 启动和程序终止.

...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.

这篇关于传递参数1会从指针目标类型中丢弃限定词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆