警告的意思。 [英] Warning meaning.

查看:72
本文介绍了警告的意思。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

Happy Solstice!

请问以下内容。


以下是摘录一个练习程序。


main(...){

if(argc 1&& mystrcomp(argv [1]," -n ;)== 0)/ * argv是-n /

****** /

.......}


int mystrcomp(char * s ,char * t){....}


我收到与星号标记的行有关的以下警告。

"警告:传递参数1''strcomp''从
指针目标类型中丢弃限定符。


我相信我会有更多问题,但究竟是什么这个

警告意味着什么?


提前谢谢。

Hi All,
Happy Solstice!
May I ask the following.

The following is a brief excerpt of a practice program.

main(...){
if (argc 1 && mystrcomp(argv[1], "-n") == 0) /* argv is "-n" /
******/
.......}

int mystrcomp( char *s, char *t){....}

I get the following warning related to the line marked by asterisks.
"Warning:passing argument 1 of ''strcomp'' discards qualifiers from
pointer target type."

I am sure I will have some more questions, but what exactly does this
warning mean?

thanks, in advance.

推荐答案

mdh说:
mdh said:

大家好,

Happy Solstice!
Hi All,
Happy Solstice!



< grump>

我们做愚人节,就是这样。没有至日,没有斋月,没有

christmases,没有divalis,没有nuffink。 4月1日(或4月1日,某些

行星)。

< / grump>

<grump>
We do April Fool''s Day, and that''s it. No solstices, no ramadans, no
christmases, no divalis, no nuffink. Just 1 April (or April 1, on some
planets).
</grump>


请问以下问题。


以下是练习计划的简要摘录。


main(...){

if(argc 1&& mystrcomp(argv [1]," -n")== 0)/ * argv是" -n" /

****** /

......}


int mystrcomp(char * s, char * t){....}


我收到与星号标记相关的以下警告。

"警告:传递参数1 ''strcomp''从
指针目标类型中丢弃限定符。


我相信我还会有更多问题,但具体到底是什么

警告意味着什么?
May I ask the following.

The following is a brief excerpt of a practice program.

main(...){
if (argc 1 && mystrcomp(argv[1], "-n") == 0) /* argv is "-n" /
******/
......}

int mystrcomp( char *s, char *t){....}

I get the following warning related to the line marked by asterisks.
"Warning:passing argument 1 of ''strcomp'' discards qualifiers from
pointer target type."

I am sure I will have some more questions, but what exactly does this
warning mean?



这意味着你的编译器骗你,假装字符串

文字是const,而不仅仅是常量。


尽管如此,如果您所做的只是比较字符串,那么它会对你造成这样的指示:


int mystrcomp(const char * s,const char * t)


作为一个令人愉快的副作用,那个虚假的警告应该消失在

薄雾。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名中, - www。

It means your compiler is lying to you, by pretending that string
literals are const, rather than merely constant.

Nevertheless, if all you''re doing is comparing strings, it will do you
no harm to make those pointers const:

int mystrcomp(const char *s, const char *t)

and as a pleasant side-effect, that spurious warning should vanish into
the mist.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


mdh< md ** @ comcast.netwrites:
mdh <md**@comcast.netwrites:

以下是练习计划的简要摘录。


main(...){

if(argc 1&& mystrcomp(argv [1]," -n")== 0)/ * argv是" -n" /

****** /

......}


int mystrcomp(char * s, char * t){....}


我收到与星号标记相关的以下警告。

"警告:传递参数1 ''strcomp''从
指针目标类型中丢弃限定符。


我相信我还会有更多问题,但具体到底是什么

警告意味着什么?
The following is a brief excerpt of a practice program.

main(...){
if (argc 1 && mystrcomp(argv[1], "-n") == 0) /* argv is "-n" /
******/
......}

int mystrcomp( char *s, char *t){....}

I get the following warning related to the line marked by asterisks.
"Warning:passing argument 1 of ''strcomp'' discards qualifiers from
pointer target type."

I am sure I will have some more questions, but what exactly does this
warning mean?



这是一个非常好的例子,说明为什么我们要求人们发布*确切的*

代码和错误消息(复制粘贴) ,不要重新打字。


你的错误信息是指一个函数strcomp,但你的代码

声明并调用一个函数叫做mystrcomp。我可以猜到

这只是一个错字,但是如果你复制并粘贴了你的实际代码我就不会猜测。
不必猜测。 br />

假设strcomp真的是mystrcomp,你的编译器是抱怨第一个参数,即argv [1]。
。假设

argv是main的常用参数(我们不能确定

),你必须自己声明 - 就在你所在的地方已经写了

" main(...)" ;.


是一个声明,你的mystrcomp()函数可以在

您在哪里调用它?


将您的程序减少到一个较小的*完整*版本,该版本显示

同样的问题。给我们一些我们可以尝试的东西。


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *< http:// users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

This is a very good illustration of why we ask people to post *exact*
code and error messages (copy-and-paste, don''t re-type).

Your error message refers to a function "strcomp", but your code
declares and calls a function called "mystrcomp". I could guess that
it''s just a typo, but if you had copy-and-pasted your actual code I
wouldn''t have to guess.

Assuming that "strcomp" is really "mystrcomp", your compiler is
complaining about the first argument, which is argv[1]. Assuming that
argv is the usual parameter to main (we can''t be certain of that
either), you have to declare it yourself -- right where you''ve written
"main(...)".

Is a declaration for your mystrcomp() function visible at the point
where you''ve called it?

Reduce your program to a smaller *complete* version that exhibits the
same problem. Give us something we can try ourselves.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


6月22日,1 :上午36点,Richard Heathfield< r ... @ see.sig.invalidwrote:

< grump>
On Jun 22, 1:36 am, Richard Heathfield <r...@see.sig.invalidwrote:
<grump>

> ........

< / grump>
>........
</grump>



对不起......没有冒犯意味着。

Sorry...no offense meant.


main(...){

if(argc 1&& mystrcomp(argv [1]," -n")== 0)/ * argv is-n ; /

****** /

......}
main(...){
if (argc 1 && mystrcomp(argv[1], "-n") == 0) /* argv is "-n" /
******/
......}


int mystrcomp(char * s,char * t){....}
int mystrcomp( char *s, char *t){....}


我收到与星号标记的行有关的以下警告。

"警告:传递''strcomp'的参数1'会从

指针目标类型中丢弃限定符。
I get the following warning related to the line marked by asterisks.
"Warning:passing argument 1 of ''strcomp'' discards qualifiers from
pointer target type."



这意味着你的编译器正在骗你,假装该字符串

literals是const,而不仅仅是常数。

It means your compiler is lying to you, by pretending that string
literals are const, rather than merely constant.



理查德...从我们之前的讨论中,我认为字符串文字

喜欢hello world是不变的?你能再解释一下

你的意思是文字是常数,而不仅仅是常数。


Richard...from our previous discussions, I thought a string literal
like "hello world" was a constant? Could you explain a little further
what you mean by "literals are const, rather than merely constant."


>

尽管如此,如果你所做的只是比较字符串,它会对你有所帮助

使这些指针变得无害:


int mystrcomp(const char * s,const char * t)


作为一个令人愉快的副作用,那个虚假警告应该消失在

雾。
>
Nevertheless, if all you''re doing is comparing strings, it will do you
no harm to make those pointers const:

int mystrcomp(const char *s, const char *t)

and as a pleasant side-effect, that spurious warning should vanish into
the mist.



.....这正是发生的事情。

.....which is exactly what happened.


这篇关于警告的意思。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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