From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 474 invoked by alias); 21 May 2008 04:41:13 -0000 Received: (qmail 367 invoked by uid 48); 21 May 2008 04:40:30 -0000 Date: Wed, 21 May 2008 04:41:00 -0000 Message-ID: <20080521044030.366.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug objc/36283] When a class method, pointed by id, returns float, it returns wrong value In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "jongampark at sbcglobal dot net" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-05/txt/msg01616.txt.bz2 ------- 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 it’s asked to perform), can’t 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