I have the following code and I want to use increment with macro:
#include <iostream>
#define ABS(x) ((x) < 0 ? -(x) : (x))
int main(int argc, char** argv)
{
int x = 5;
const int result = ABS(x++);
std::cout << "R: " << result << std::endl;
std::cout << "X: " << x << std::endl;
return EXIT_SUCCESS;
}
But output will be incorrect:
R: 6
X: 7
Is it possible to somehow use macros with an increment, or should this be abandoned altogether?