public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug objc/36283]  New: When a class method, pointed by id, returns float, it returns wrong value
@ 2008-05-20 20:45 jongampark at sbcglobal dot net
  2008-05-20 21:03 ` [Bug objc/36283] " pinskia at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: jongampark at sbcglobal dot net @ 2008-05-20 20:45 UTC (permalink / raw)
  To: gcc-bugs

(I don't know if this happens only to gcc 3.4.5 from the MingW and if it was
solved already in newer versions.)

I made two classes inherited from a common parent class in Objective-C.
The two children classes have methods, "- (float) data" and "- (int) data"
respectively. They are for returning data value contained in each classes, or
more accurately, their class instances.

I would like to show a code example.
@implementation GFloat : Generics
- (id) add:(id) aVal
{
    float value, value2;
    int value3;

    value = [aVal data]; // This can't return a float value in "aVal"
correctly.

    value2 = returnFloat(); // C function returns a float value correctly.
    value3 = returnInt();   // C function returns a int value correctly.

    printf("%f, %f and %d\n", value, value2, value3);

   ....

The method, "add", takes the aVal as an id type.
By sending "data" message to aVal, it calls GFloat's data method successfully.
So, inside of the data method/message, correct data value is fetched and
returned. However, from the caller's line, which is shown above, the returned
value is something other than what the "data" message returned.

When the aVal is casted to (GFloat *), its returned value is correct.

Is it weird because it returns wrong value although correct method is called.

I would like to test the code at home with my MacOS X machine.


-- 
           Summary: When a class method, pointed by id, returns float, it
                    returns wrong value
           Product: gcc
           Version: 3.4.5
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: objc
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jongampark at sbcglobal dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36283


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug objc/36283] When a class method, pointed by id, returns float, it returns wrong value
  2008-05-20 20:45 [Bug objc/36283] New: When a class method, pointed by id, returns float, it returns wrong value jongampark at sbcglobal dot net
@ 2008-05-20 21:03 ` pinskia at gcc dot gnu dot org
  2008-05-20 21:06 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-05-20 21:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2008-05-20 21:02 -------
Actually I don't think this is a bug.  What is happening is the id is a generic
class type so the compiler needs to decide at compile time what the type is
being returned.  In this case it decides on the one the user did not want.  The
cast will chose the correct one.  Now at runtime is selects the correct type
but of course by the time you get there it is already messed up.

-- Pinski


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |normal


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36283


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug objc/36283] When a class method, pointed by id, returns float, it returns wrong value
  2008-05-20 20:45 [Bug objc/36283] New: When a class method, pointed by id, returns float, it returns wrong value jongampark at sbcglobal dot net
  2008-05-20 21:03 ` [Bug objc/36283] " pinskia at gcc dot gnu dot org
@ 2008-05-20 21:06 ` pinskia at gcc dot gnu dot org
  2008-05-21  2:57 ` jongampark at sbcglobal dot net
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-05-20 21:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2008-05-20 21:05 -------
Try using -Wstrict-selector-match and see what you get.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36283


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug objc/36283] When a class method, pointed by id, returns float, it returns wrong value
  2008-05-20 20:45 [Bug objc/36283] New: When a class method, pointed by id, returns float, it returns wrong value jongampark at sbcglobal dot net
  2008-05-20 21:03 ` [Bug objc/36283] " pinskia at gcc dot gnu dot org
  2008-05-20 21:06 ` pinskia at gcc dot gnu dot org
@ 2008-05-21  2:57 ` jongampark at sbcglobal dot net
  2008-05-21  3:01 ` jongampark at sbcglobal dot net
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jongampark at sbcglobal dot net @ 2008-05-21  2:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jongampark at sbcglobal dot net  2008-05-21 02:57 -------
(In reply to comment #2)
> Try using -Wstrict-selector-match and see what you get.
> 

I will try that. Thanks.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36283


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug objc/36283] When a class method, pointed by id, returns float, it returns wrong value
  2008-05-20 20:45 [Bug objc/36283] New: When a class method, pointed by id, returns float, it returns wrong value jongampark at sbcglobal dot net
                   ` (2 preceding siblings ...)
  2008-05-21  2:57 ` jongampark at sbcglobal dot net
@ 2008-05-21  3:01 ` jongampark at sbcglobal dot net
  2008-05-21  4:41 ` jongampark at sbcglobal dot net
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jongampark at sbcglobal dot net @ 2008-05-21  3:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from jongampark at sbcglobal dot net  2008-05-21 03:00 -------
(In reply to comment #1)
> Actually I don't think this is a bug.  What is happening is the id is a generic
> class type so the compiler needs to decide at compile time what the type is
> being returned.  In this case it decides on the one the user did not want.  The
> cast will chose the correct one.  Now at runtime is selects the correct type
> but of course by the time you get there it is already messed up.
> 
> -- Pinski
> 

That was my first idea. So, that is why I tested if correct method is called,
and it returns things correctly. Once it knows what value to return and through
which register, I guess it means just the interpretation of the returned data.
So, I tried casting the returned value to float. But it didn't fix the problem.
The only way to fix it is to cast the pointer to the object of which method is
called.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36283


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug objc/36283] When a class method, pointed by id, returns float, it returns wrong value
  2008-05-20 20:45 [Bug objc/36283] New: When a class method, pointed by id, returns float, it returns wrong value jongampark at sbcglobal dot net
                   ` (3 preceding siblings ...)
  2008-05-21  3:01 ` jongampark at sbcglobal dot net
@ 2008-05-21  4:41 ` jongampark at sbcglobal dot net
  2008-05-21 14:57 ` jongampark at sbcglobal dot net
  2008-12-28 21:39 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: jongampark at sbcglobal dot net @ 2008-05-21  4:41 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1848 bytes --]



------- 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug objc/36283] When a class method, pointed by id, returns float, it returns wrong value
  2008-05-20 20:45 [Bug objc/36283] New: When a class method, pointed by id, returns float, it returns wrong value jongampark at sbcglobal dot net
                   ` (4 preceding siblings ...)
  2008-05-21  4:41 ` jongampark at sbcglobal dot net
@ 2008-05-21 14:57 ` jongampark at sbcglobal dot net
  2008-12-28 21:39 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: jongampark at sbcglobal dot net @ 2008-05-21 14:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jongampark at sbcglobal dot net  2008-05-21 14:57 -------
(In reply to comment #2)
> Try using -Wstrict-selector-match and see what you get.
> 

The gcc 3.4.5 came from the MingW doesn't recognize the flag.
And even without it, it warns multiply declared methods.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36283


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug objc/36283] When a class method, pointed by id, returns float, it returns wrong value
  2008-05-20 20:45 [Bug objc/36283] New: When a class method, pointed by id, returns float, it returns wrong value jongampark at sbcglobal dot net
                   ` (5 preceding siblings ...)
  2008-05-21 14:57 ` jongampark at sbcglobal dot net
@ 2008-12-28 21:39 ` pinskia at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-12-28 21:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from pinskia at gcc dot gnu dot org  2008-12-28 21:38 -------
THis is not a bug as explained, the compiler needs to decide what kind of
method needs to be called including the return value.  So the compiler is guess
it returns an int instead of the float one.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36283


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-12-28 21:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-20 20:45 [Bug objc/36283] New: When a class method, pointed by id, returns float, it returns wrong value jongampark at sbcglobal dot net
2008-05-20 21:03 ` [Bug objc/36283] " pinskia at gcc dot gnu dot org
2008-05-20 21:06 ` pinskia at gcc dot gnu dot org
2008-05-21  2:57 ` jongampark at sbcglobal dot net
2008-05-21  3:01 ` jongampark at sbcglobal dot net
2008-05-21  4:41 ` jongampark at sbcglobal dot net
2008-05-21 14:57 ` jongampark at sbcglobal dot net
2008-12-28 21:39 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).