* str ++未定义? [英] *str++ is undefined?

查看:181
本文介绍了* str ++未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码:


* str ++ = tolower(* str);


gcc抱怨


警告:对'str''的操作可能未定义


我正在收到''di'的类似警告''和'''''中的''和''''
di = ++ di%dn;




bi = ++ bi%BUFSIZ;


我把它递增并一起评估是不确定的

bahavior?这是什么规则?


谢谢,

迈克


$ gcc -v

从/usr/libexec/gcc/darwin/ppc/3.3/specs阅读规格

线程模型:posix

gcc版本3.3 20030304(Apple Computer,Inc .build 1666)

I have some code:

*str++ = tolower(*str);

that gcc is complaining about:

warning: operation on `str'' may be undefined

I''m getting similar warnings for ''di'' and ''bi'' in:

di = ++di % dn;

and

bi = ++bi % BUFSIZ;

I take it incrementing and evaluating together is undefined
bahavior? What''s the rule?

Thanks,
Mike

$ gcc -v
Reading specs from /usr/libexec/gcc/darwin/ppc/3.3/specs
Thread model: posix
gcc version 3.3 20030304 (Apple Computer, Inc. build 1666)

推荐答案

gcc -v

从/ usr / libexec / gcc / darwin / ppc /阅读规格3.3 / specs

线程模型:posix

gcc版本3.3 20030304(Apple Computer,Inc。build 1666)
gcc -v
Reading specs from /usr/libexec/gcc/darwin/ppc/3.3/specs
Thread model: posix
gcc version 3.3 20030304 (Apple Computer, Inc. build 1666)


Michael B Allen写道:
Michael B Allen wrote:

* str ++ = tolower(* str);

gcc抱怨
我在'di''和''''中收到类似的警告:

di = ++ di%dn;


bi = ++ bi%BUFSIZ;

我把它递增一起评估是不确定的行为?这是什么规则?

*str++ = tolower(*str);

that gcc is complaining about:

warning: operation on `str'' may be undefined

I''m getting similar warnings for ''di'' and ''bi'' in:

di = ++di % dn;

and

bi = ++bi % BUFSIZ;

I take it incrementing and evaluating together is undefined
bahavior? What''s the rule?




编号您使用的是未定义的值,因为++实际上可能是

之前生效或者在使用相同的

变量之后。对于单独的字符串,同样的事情也没问题:


* s1 ++ = tolower((unsigned char)* s2 ++);


注意你除非s2已经是类型

unsigned char,否则需要在此处进行转换。 char不会。


-

"如果你想通过groups.google.com发布后续内容,不要使用

破损的回复链接在文章的底部。点击

" show options"在文章的顶部,然后点击

回复在文章标题的底部。 - Keith Thompson



No. You are using an undefined value, because the ++ may actually
take effect either before or after the other use of the same
variable. The same thing would be fine for separate strings:

*s1++ = tolower((unsigned char) *s2++);

Note that you need the cast here unless s2 is already of type
unsigned char. char won''t do.

--
"If you want to post a followup via groups.google.com, don''t use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson


2005年3月19日星期六01:30:23 -0500,CBFalconer写道:
On Sat, 19 Mar 2005 01:30:23 -0500, CBFalconer wrote:

* str ++ = tolower(* str);

gcc抱怨

警告:对`str'的操作'可能未定义

*str++ = tolower(*str);

that gcc is complaining about:

warning: operation on `str'' may be undefined



否。您使用的是未定义的值,因为++在实际使用相同变量之前或之后可能会产生
效果。



No. You are using an undefined value, because the ++ may actually take
effect either before or after the other use of the same variable.




那是愚蠢的。表达式的右侧必须在

之前进行评估。歧义究竟在哪里?


Mike



That''s stupid. The right side of the expression must be evaluated before
an assignment can be made. Where is the ambiguity exactly?

Mike


这篇关于* str ++未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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