且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

* p ++ = tolower(* p));

更新时间:2023-08-21 17:52:04

Gunvant Patil说:
Gunvant Patil said:

>

* p ++ = tolower(* p));


是此行为中定义的标准是什么?
>
*p++ = tolower(*p));

is this behaviour defined in standards?



我看了一眼,立即知道了答案。 不......呃,嗯,

序列点,所以是的......呃,坚持,呃,如果...,嗯......

总是一个很好的暗示,***重新编写它以反映你实际意味着什么
(从代码中不清楚) 。


-

Richard Heathfield

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

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

I took one look at it and immediately knew the answer. "No... er, hmm,
sequence points, so yes... er, hang on, er, what if..., hmm..." which
is always a good hint that it''s better to re-write it to reflect what
you actually mean (which isn''t clear from the code).

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


Gunvant Patil写道:
Gunvant Patil wrote:

* p ++ = tolower(* p));


是标准中定义的这种行为吗?
*p++ = tolower(*p));

is this behaviour defined in standards?



它被定义为未定义。所以不要这样做。

It''s defined to be undefined. So don''t do it.


假设p指向ABCD


执行上述声明后在BSD上

*(p-1)是a。意味着tolower以非递增的值传递p


在linux上,它是b。意味着tolower以递增的值传递

p ??
Suppose p points to "ABCD"

On BSD after executing above statement
*(p-1) is "a" means tolower is passed with non incremented value of p

On linux it is "b" means tolower is passed with incremented value of
p ??



在任何一个系统中,它意味着做你喜欢的事,不管什么方便,我不需要关心。 ;。结果可能是编译器 - 编写者

找到方便的任何东西。如果您非常幸运,编译器可能会在某些情况下通知您未定义并且这样说;但在一般情况下,它无法说明。如果你非常不走运,编译器会在执行语句时注意并植入代码来运行Rogue。

如果你经常不走运,一切都会按你喜欢的方式工作,直到你升级编译器/改变优化级别/更改

一个明显不相关的编译器选项/运行不同的代码

处理器在同一系列/端口代码到不同的实现/

在有价值的客户面前进行演示。


总是一个明天BOOM。


-

Ivanova Hedgehog

美好时光曾经好多了。

On either system it means "do what you like, whatever''s convenient, I
don''t care.". The result will probably be whatever the compiler-writer
found convenient. If you''re astonishingly lucky, the compiler might
notice in some cases that you''re being undefined and say so; but in
general it can''t tell. If you''re astonishingly unlucky, the compiler
will notice and plant code to run Rogue when you execute the statement.
If you''re routinely unlucky, everything will work as you like until the
day you upgrade the compiler / change the optimisation level / change
an apparently unrelated compiler option / run the code on a different
processor in the same family / port the code to a different implementation /
give a demonstration in front of a valued client.

Always a BOOM tomorrow.

--
Ivanova Hedgehog
The "good old days" used to be much better.




Gunvant Patil写道:

Gunvant Patil wrote:

* p ++ = tolower(* p));


是标准中定义的这种行为吗?
*p++ = tolower(*p));

is this behaviour defined in standards?



不,这是一个未定义的行为。您可能会或可能不会获得

明智的结果,具体取决于编译器和主机

系统。

No, it''s a case of undefined behaviour. You might or might not get
sensible results depending, among others, on the compiler and the host
system.