0

warning: operation on ‘left’ may be undefined [-Wsequence-point] right = right + left - (left = right);

{
    int right = 5, left = 14;
    std::cout << right << " " << left << std::endl;
    right = right + left - (left = right);
    std::cout << right << " " << left << std::endl;
}
  • And such code is used in practice or not? – Programming Lover Mar 30 '18 at 12:31
  • It does not compile? Why would it be used? To save a word? – dbrank0 Mar 30 '18 at 12:32
  • Related: [How to swap two numbers without using a temporary variable?](https://www.geeksforgeeks.org/swap-two-numbers-without-using-temporary-variable/) – Scheff's Cat Mar 30 '18 at 12:38
  • I have not seen this technique in embedded systems nor platform applications. The swap algorithms I've encountered either use a temporary variable/object or use a processor instruction for swapping. I would say that such code is not used in the real world. – Thomas Matthews Mar 30 '18 at 14:06

0 Answers0