Hi,
This example is taken from the cpp faq by Marshall Cline, section 9.5.
// A macro that returns the absolute value of i
#define unsafe(i) \
( (i) >= 0 ? (i) : -(i) )
// An inline function that returns the absolute value of i
inline
int safe(int i)
{
return i >= 0 ? i : -i;
}
int f();
void userCode(int x)
{
int ans;
ans = unsafe(x++); // Error! x is incremented twice
ans = unsafe(f()); // Danger! f() is called twice
ans = safe(x++); // Correct! x is incremented once
ans = safe(f()); // Correct! f() is called once
}
My question: What is it that makes x get incremented twice in
ans = unsafe(x++) ?
Regards
आलोक
--
Can't see Hindi? http://geocities.com/alkuma/seehindi.html
Discuss devanagari at http://groups.yahoo.com/group/devanaagarii/
alok_kumar à¤à¤Ÿ softhome डॉट net
This example is taken from the cpp faq by Marshall Cline, section 9.5.
// A macro that returns the absolute value of i
#define unsafe(i) \
( (i) >= 0 ? (i) : -(i) )
// An inline function that returns the absolute value of i
inline
int safe(int i)
{
return i >= 0 ? i : -i;
}
int f();
void userCode(int x)
{
int ans;
ans = unsafe(x++); // Error! x is incremented twice
ans = unsafe(f()); // Danger! f() is called twice
ans = safe(x++); // Correct! x is incremented once
ans = safe(f()); // Correct! f() is called once
}
My question: What is it that makes x get incremented twice in
ans = unsafe(x++) ?
Regards
आलोक
--
Can't see Hindi? http://geocities.com/alkuma/seehindi.html
Discuss devanagari at http://groups.yahoo.com/group/devanaagarii/
alok_kumar à¤à¤Ÿ softhome डॉट net
Comment