Vlad
Have fun figuring out what went wrong
Anonymous
—a is 3, and it makes a == 3 and then a— is also three. Logically —a * a— must be 3*3
it can happen in any order. what happens if the assembly does this - a-- value computation, --a side effect computation, a-- side effect computation, --a value computation
Aakash
ifndr
+1, absolutely perfect answer.
Programmer
it can happen in any order. what happens if the assembly does this - a-- value computation, --a side effect computation, a-- side effect computation, --a value computation
This program seems to be equivalent to this: #include <iostream> using namespace std; int mA(int& a) { return --a; } int Am(int& a) { return a--; } int main() { int a = 4; int b = mA(a) * Am(a); cout<< b; cin.get(); }
Vlad
Also what function will be called first depends on the mood of your compiler. It is not specified
Pavel
ifndr
Not sure if you wanted to answer to my message, but if you did, this still not a problem of a specific compiler
Vlad
Have a look at c++ standard
Vlad
You've got a whole new world of discovery ahead of you :P
Anonymous
LMAO
Programmer
Vlad
any counterexamples in any compiler?
Compiler implements standard
Vlad
Do you get it or not?
Anonymous
any counterexamples in any compiler?
You shouldn't use compiler as a reference
Anonymous
You should use C++ standard as a reference
Programmer
Do you get it or not?
I'm interested to know if any compiler designer has changed the order of execution using the freedom given in the standard.
Vlad
In the way that is the most convenient for their implementation
Joo
Please can i code of a simple calculator which can add more than two inputs in c++?
Joo
Without using enumerators?
Programmer
They did
This is why asked for a counterexample in which in f()*g(), g() is run first.
#amu💕
Please help me....i have a question my first question has 1:- write a java program to print half pyramid using * Like this * * * * * * * * * * * * * * *
Joo
I shall permit you
Get a code rather?
Pavel
I'm interested to know if any compiler designer has changed the order of execution using the freedom given in the standard.
The order may even be different for different expressions produced by the same compiler (e.g. if some function call need data to be fetched it can be processed the last), haven't examined cases like that (don't see reasons to examine things that can't be related on)
Vlad
Get a code rather?
So you ask us to google up an example instead of you?
Vlad
You could've done that already instead of asking lmao
Vlad
What?
Have you tried to ask in the java chat, so it wouldn't be offtop?
Vlad
Legend has it that it works like a charm
Vlad
@en_it_chats
Programmer
The order may even be different for different expressions produced by the same compiler (e.g. if some function call need data to be fetched it can be processed the last), haven't examined cases like that (don't see reasons to examine things that can't be related on)
I know about these freedoms. I'm interested in examples in which the order of execution of operand functions is from right to left. Just like —a * a— in gcc. I cannot produce an example....
Wojak
Legend has it that it works like a charm
Seeing your mugshot, I'm too afraid to not believe you
#amu💕
Why?
klimi
Why?
it was offtopic
#amu💕
Ok in this group discuss only on c++ program?
klimi
you accepted that... you should have read them
Anonymous
This is why asked for a counterexample in which in f()*g(), g() is run first.
Can you prove that in f() * g(), f() is always evaluated first?
#amu💕
read rules
Ok...excuse me i readied the rules
Programmer
Can you prove that in f() * g(), f() is always evaluated first?
The output of a compiler is a proof. But the standard does not confirm such outputs. Perhaps the standard has a reason for giving such freedoms. I'm interested in an example in which a compiler actually uses the freedom in an expression like f()*g().
ⓐⓜⓘⓡⓡⓔⓩⓐⓦ
Write a program that calculates the answer of the Lorentz differential equation with the given initial conditions and the data output To draw
Anonymous
Right, I meant that the compilers don't have problems :)
sorry i was wrong here. code that exhibits undefined behaviour can still be well-formed...
Anonymous
ifndr
...it's just the standard imposes no restriction on what happens on such behaviour. [intro.abstract] 5. ...this document places no requirement on the implementation executing that program with that input (not even with regard to operations preceding the first undefined operation).
Programmer
counterexamples disprove, examples don't prove.
Exactly: I'm looking for a example code and a C++ compiler in which in an expression like f()*g() the function g() is executed first. This is my question if anyone can answer.
ⓐⓜⓘⓡⓡⓔⓩⓐⓦ
excuse me?
Can you solve it??
klimi
Can you solve it??
of course, it seems very easy
Anonymous
/c++
ⓐⓜⓘⓡⓡⓔⓩⓐⓦ
of course, it seems very easy
Thats good I wait for you Thank youuuu❤❤❤
Anonymous
/resources
ⓐⓜⓘⓡⓡⓔⓩⓐⓦ
Write as far as you know🙏🙏🙏🙏
shayan
Hi
ⓐⓜⓘⓡⓡⓔⓩⓐⓦ
okay
Were you able to write to some extent?
klimi
Were you able to write to some extent?
i am working on other project right now
Anonymous
https://godbolt.org/z/b8jzTs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=11751 "there does not even have be a constancy in the behavior across optimization levels, types or anything else." and just because there is an apparent consistency in some examples doesn't mean we should start relying on that.
ⓐⓜⓘⓡⓡⓔⓩⓐⓦ
Programmer
https://godbolt.org/z/b8jzTs
Thanks but I'm looking for an example about operands of an operator like "*". In your example the order of the execution of arguments of printf is from right to left. printf is not an operator. :)
Anonymous
Thanks but I'm looking for an example about operands of an operator like "*". In your example the order of the execution of arguments of printf is from right to left. printf is not an operator. :)
> In your example the order of the execution of arguments of printf is from right to left huh? gcc and clang evaluated differently > printf is not an operator the undefined behaviour comes from a lack of sequence points in both cases
Anonymous
https://godbolt.org/z/vrGzKn this gets even crazier with different values
Anonymous
oh and i didn't use C++ intentionally because sequence points are easier to understand than the "sequenced before" rules
Pavel
Pretty difficult to catch cases like that since there are no rules
Programmer
> In your example the order of the execution of arguments of printf is from right to left huh? gcc and clang evaluated differently > printf is not an operator the undefined behaviour comes from a lack of sequence points in both cases
I meant you found a compiler that executed arguments of a function from right to left. With a Borland C++ compiler I had another one in which the order of execution of arguments changes if one changes the calling convention.. But native operators are not functions... can you find an example in which operands of a native operator (not a user-defined one), is executed from right to left? Native operators are different.... Such example can be helpful to demonstrate some unreliable codes...