------- Comment #5 from jongampark at sbcglobal dot net 2008-05-21 04:40 ------- I tried it on my MacBook with 4.0.1 version of gcc. ( provided by Apple Inc. )
- (void)add:(id)valObj { float temp_value; // If I cast this way temp_value = (float)[valObj value]; // I changed "data" to "value", to see if I had misfortune in choosing message name. // it displays a message, "error:pointer value used where a floating point value was expected. It seems to me that it means the return value by sending message "value" is recognized as a pointer. // If I cast this way temp_value = [(GFloat *)valObj value]; It compiles without any problem and returns correct value. So, does it mean that we can't rely on the returned value when using id? By the way, the Objective-C programming language manual from Apple describes : Return and Argument Types In general, methods in different classes that have the same selector (the same name) must also share the same return and argument types. This constraint is imposed by the compiler to allow dynamic binding. Because the class of a message receiver (and therefore class-specific details about the method its asked to perform), cant be known at compile time, the compiler must treat all methods with the same name alike. When it prepares information on method return and argument types for the runtime system, it creates just one method description for each method selector. Then... wouldn't it be better to present error message in the case of my test code? Because the return type of the same message of GInt, and GFloat are different, i.e. int and float, respectively, it violates the explanation above. Instead of allowing the compilation, it would be good to prevent compilation or somewhat better error message. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36283