Does the following code invoke Undefined Behavior?
-
23-09-2019 - |
문제
#include <iostream>
#include <cmath>
#define max(x,y) (x)>(y)? (x): (y)
int main() {
int i = 10;
int j = 5;
int k = 0;
k = max(i++,++j);
std::cout << i << "\t" << j << "\t" << k << std::endl;
}
해결책
사용자가 해당하지 않고 SpjobDefinition 클래스에서 직접 상속 된 경우 자식 작업을 사용하지 않으므로 기본적으로 기본 메소드를 실행할 필요가 없습니다. 그러나 멀티 상속 된 경우 (Whata Word i) spjobDefinition이 실행하려는 결정.
다른 팁
Well, there certainly are a lot of problems with it.
- max is actually computing min
- increment operators are doubled on whatever choice is selected since you are using a macro
- using postfix/prefix increments is just thrown in to confuse, but doesn't have a lot of bearing on the problem.
This code will produce the same results each time run, so no, it's not undefined. At the cout:
i = 11
k = 7
j = 7
This sounds like a bad homework problem. :)
제휴하지 않습니다 StackOverflow