[ CnUnix ] in KIDS 글 쓴 이(By): zeo (ZeoDtr) 날 짜 (Date): 1994년02월05일(토) 16시38분36초 KST 제 목(Title): [A] ++a + b + ++a : 결론 결론부터 이야기해서, TC, gcc, cc 모두 옳습니다. 다른 결과가 나오더라도 말입니다. 그 문장의 해석은 컴파일러 마음대로입니다. 다음의 글은 K&R The C Programming Language (1판?) 의 50쪽에 나오는 겁니다. 참조하시죠. Function calls, nested assignment statements, and increment and decrement operators cause "side effects" - some variable is changed as a byproduct of the evaluation of an expression. In any expression involving side effects, there can be subtle dependencies on the order in which variables taking part in the expression are stored. One unhappy situation is typified by the statement a[i] = i++; The question is whether the subscript is the old value of 'i' or the new. The compiler can do this in different ways, and generate different answers depending on its intepretation. When side effects (assignments to actual variables) takes place is left to the descretion of the compiler, since the best order strongly depends on machine architecture. The moral of this discussion is that writing code which depends on order of evaluation is bad programming practice in any language. Naturally, it is necessary to know what things to avoid, but if you don't know 'how' they are done in various machines, that innocence may help to protect you. (The C verifier 'lint' will detect most dependencies on order of evaluation.) 뱀다리: 확실히 알지도 못하고 특정 회사의 컴파일러를 욕한다는 것은 좀 무례한 행위 같군요. (저는 Borland와는 아무런 상관이 없습니다!) 불쌍한 TC, optimize해 보겠다고 애쓰는 걸 몰라주고 욕이나 먹다니... 우리 모두 코딩 잘 합시다. 세상 모든 컴파일러들의 비위에 맞게... ZZZZZZ zZZ eeee ooo zZ Eeee O O ZZZZZZ Eeee OoO |