Re: Mixing Objective C and C++
Re: Mixing Objective C and C++
- Subject: Re: Mixing Objective C and C++
- From: Bert Torfs <email@hidden>
- Date: Tue, 25 Jan 2005 22:20:49 +0100
Shawn,
I m currently stuck with these floats. The new view uses NSDecimals
though. When I attack the model I'll convert it to NSDecimal (and
coredata) as well so I can throw away all these rounding error catch
routines.
I am working with serialized C++ objects, but the Objective-C object,
as it does not hold any data, is not serialized. If I step through the
code with the debugger, the instance variable 'localBalance' has value
91797,... inside the localBalance() method (inspecting self)
double localBalance
{
return localBalance; //Value = 91797.283316716232 according to the
debugger
}
It seems to me as if C++ and objectiveC store doubles differently, and
the compiler mixes the 2 in my case. I guess I can solve it by
delegating the caching of the Objective C objects to a helper object,
so the C++ objects remain 'pure'.
Thanks a lot,
Bert
On 25-jan-05, at 21:32, Shawn Erickson wrote:
On Jan 25, 2005, at 11:51 AM, Bert Torfs wrote:
Hi all,
I am writing a program where the model is written in C++ (legacy),
the view in Objective C and the controller something in between.
Every C++ object has an objective C counterpart that acts as a
pass-thru to its methods. These objects are created and released as
needed. I have not touched the C++ objects until now.
For performance, I added an instance variable to every C++ object
that holds its Objective C counterpart. But now simple things like
double theAmount;
theAmount = currentDebit->localBalance();
do not work anymore. While localBalance equals 91797.283316716232,
theAmount equals -6.9988350839989206e-268 after the function call.
(the method 'localBalance' does nothing but returning localBalance.).
Any idea?
Ignoring the problematic use of floating point numbers for what
appears to be currency...
Are you working with serialized C++ objects that when unserialized may
not reflect the changes you made to the classes when you added the
references out to the Objective-C object?
Did you rebuild everything? The vtable may be screwed up and your
localBalance() call may be hitting a different a different method
(unlikely that link errors wouldn't have been hit but who knows if you
have some type of mixed object code). Try deleting the build directory
and rebuilding things.
Showing code would help...
-Shawn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden