I tested this expression in gdb:
(gdb) p (int)[@"-1" floatValue]
$2 = 1
but
(gdb) p (int)((float)[@"-1" floatValue])
$7 = -1
comes out as I expect
Why does the first expression not return -1? Also, what is the return type of [@"-1" floatValue]?
gdb doesn’t know the return type of methods (or functions):
When you cast the expression to
int, gdb assumes that the method returns anint. So it knows it can useobjc_msgSendto send the message and treat the return value fromobjc_msgSendas anint.When you cast the expression to a
float, gdb assumes that the method returns afloat. So it knows that it should useobjc_msgSend_fpretto send the message and treat the return value as a float.This is important because: