2010-05-21

Undefined increment

#include <stdio.h>

#define COMPUTE(x,y) ((x*x*x) + (y))

int main()
{
        int num1 = 100;
        int num2 = 10;

        printf("%d\n", COMPUTE(++num1, num2));

        return 0;
}
The result is undefined in both C and C++, but the behavior is consistent and interesting. The result is in the first comment.
compute.c:10: warning: operation on ‘num1’ may be undefined
Attention by http://synsecblog.com/

1 comment: