Line 9 modifies and accesses a variable twice in the same line. C++ doesn't specify what order those modifications and accesses have to happen in. Your compiler should warn you with a message like "warning: operation on 'm' may be undefined".
---
Bu bir Google çevirisidir, lütfen herhangi bir hatayı affedin. Satır 9, aynı satırda bir değişkeni iki kez değiştirir ve erişir. C ++, bu değişikliklerin ve erişimlerin hangi sırada olması gerektiğini belirtmez. Derleyiciniz sizi "uyarı: 'm' üzerindeki işlem tanımsız olabilir" mesajı ile uyarmalıdır.
In C++, "Undefined" means that compilers are free to do whatever they want, even if it doesn't make sense to you. When you change and access a variable in the same expression, C++ does not require the changes and accesses to be in any specific order. cpp.sh's g++ selects an order that makes sense to you. Visual Studio and MinGW select a different order. This is actually easy for you to solve: just move some of your code to a new expression. Then, it should work correctly with all three compilers.
---
C ++ 'da "Undefined", derleyicilerin sizin için anlamlı olmasa bile istediklerini yapmakta serbest oldukları anlamına gelir. Bir değişkeni aynı ifadede değiştirip eriştiğinizde, C ++, değişikliklerin ve erişimlerin belirli bir sırada olmasını gerektirmez. cpp.sh's g ++, sizin için anlamlı olan bir sipariş seçer. Visual Studio ve MinGW farklı düzeni seçin. Bu, çözmeniz için aslında kolaydır: sadece kodunuzun bir kısmını yeni bir ifadeye taşıyın. Sonra, her üç derleyici ile düzgün çalışmalıdır.
1 2
constlong r = m+(i*i);
return ( r * formul(--m, ++i) );
-Albatross
(Whew, it took some work to write that paragraph in a way that Google would translate it from English > Turkish > English without ruining it. I really hope it makes some sense in Turkish, even if it's likely a pretty broken translation.)
The thing that relevance with my code is problem of gnu and windows!
the thing about my code is
Benim kodum ile alakali olan sey ise windows ve gnu müşkilatı!
my code is working in linux! Why?
The meaning of müşkil(at) is problem(s). not difficult(s).
The translation engine pages that reflected me could be different !!
bana yansiyan ceviri motoru sayfalari farkli olabilir !!
Line 9 modifies and accesses a variable twice in the same line. C++ doesn't specify what order those modifications and accesses have to happen in. Your compiler should warn you with a message like "warning: operation on 'm' may be undefined".
Hey, Albatros!
this problem is related to using an outdated gnu gcc version on cpp.sh server.
bu problem ise cpp.sh serverda güncel olmayan bir gnu gcc version kullanılması ile alakalıdir.
You're not getting it. The problem is not the compilers, the problem is your code. This line
return ( (m+(i*i)) * formul((--m),(++i)));
has undefined behavior. What that means is the language specification allows compilers to generate any machine code for it.
To fix your code you have to break up that expression in a way that the order of operations becomes defined. For example, either
1 2 3
auto a = formul(--m, ++i);
auto b = m + i * i;
return a * b;
or
1 2 3
auto b = m + i * i;
auto a = formul(--m, ++i);
return a * b;
Actually, this warning is not important because it is returning correctly.
You're making a common mistake here. You're assuming that the code is correct because you get the right answer. But as others have pointed out, your code relies on undefined behavior.
> my code is working in linux! Why?
Never equate "working" with "bug-free".
Especially when other compilers are giving you a different answer.
The failure of any particular compiler to give you a compilation warning is not an argument of correctness on your part.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
$ cat foo.c
int formul(int x, int y) {
return x+y;
}
int foo ( int m, int i ) {
return ( (m+(i*i)) * formul((--m),(++i)));
}
$ gcc -c -Wall -Wextra foo.c
foo.c: In function ‘foo’:
foo.c:6:32: warning: operation on ‘m’ may be undefined [-Wsequence-point]
return ( (m+(i*i)) * formul((--m),(++i)));
^
foo.c:6:38: warning: operation on ‘i’ may be undefined [-Wsequence-point]
return ( (m+(i*i)) * formul((--m),(++i)));
^
foo.c:6:38: warning: operation on ‘i’ may be undefined [-Wsequence-point]
GCC isn't going to be printing these warnings "for fun", it prints them because there IS a problem that needs to be fixed.