I defined a macro as follows:
#define ccpd(__X__, __Y__) (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) ? CGPointMake(__X__ * 0.416667f ,__Y__ * 0.416667f) : CGPointMake(__X__,__Y__)
Later:
CGPoint p1 = ccpd(1280, 440);
CGPoint p2 = ccpd(1024 + 256, 440);
This what I get:
(gdb) p p1
$2 = {
x = 533.333801,
y = 183.333481
}
(gdb) p p2
$3 = {
x = 1130.66675,
y = 183.333481
}
Why am I getting different results? Am I misunderstanding how a macro works?
You macro in the second case expands to something like:
which is
Add parenthesis around the macro parameters:
or better: make a proper function and let the compiler optimize it.