Path: csiph.com!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++ Subject: Re: is "x *= ++f * ++f" a valid statement ? PLO Date: Fri, 21 Jun 2024 17:35:52 -0700 Organization: None to speak of Lines: 55 Message-ID: <87v821vmon.fsf@nosuchdomain.example.com> References: MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Sat, 22 Jun 2024 02:35:52 +0200 (CEST) Injection-Info: dont-email.me; posting-host="a921bbd4938ad56818714429bbe0a6b9"; logging-data="3585641"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8Gv+iQ6ZqCb0ePl5x49HX" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:yus9HqW5UkxjhEfm00hBisLKJFk= sha1:scQSWAj6/ESTGggVsRCvqHdLq/U= Xref: csiph.com comp.lang.c++:119484 olcott writes: > On 6/21/2024 5:10 PM, Richard Damon wrote: >> On 6/21/24 5:55 PM, olcott wrote: >>> On 6/18/2024 8:53 PM, Andrey Tarasevich wrote: >>>> On 05/23/24 7:14 AM, Bonita Montero wrote: >>>>> Is "x *= ++f * ++f" a valid statement ? >>>>> Or is there implementation defined behaviour ? >>>> >>>> The question is meaningless without knowing the types of objects >>>> involved. It has no specific answer >>>> >>> >>> If it works correctly for int then it is >>> syntactically correct: >>> int x = 1; >>> int f = 1; >>> x = 1 * (2 * 3); Yes, it's syntactically valid, but that wasn't the question. >>> ++f could be defined as exit(0) for some UDT. >>> >> But, the DEFINITON of ++ doesn't requring that one of the f's are >> incremented first, then you use the value, then the othero >> one. (unless the rules were actually changed). >> > > When we assume the *= assigns > the result of the RHS * the LHS to the LHS > "x *= ++f * ++f" > > means x = x * (++f * ++f) > thus cannot have implementation defined behavior. We don't have to assume anything. The meaning of "*=" is well known (and you left out the fact that x is evaluated only once). It doesn't have implementation-defined behavior. It has undefined behavior. The C++ standard says so: If a side effect on a memory location is unsequenced relative to either another side effect on the same memory location or a value computation using the value of any object in the same memory location, and they are not potentially concurrent, the behavior is undefined. If x and f are objects of type int, then the evaluation of `++f * ++f` has undefined behavior because the two modifications of f are unsequenced. There isn't some limited number of possible behaviors. The standard says nothing about what happens when the expression is evaluated. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */