weird headers compiler problems
weird headers compiler problems
- Subject: weird headers compiler problems
- From: crucial felix <email@hidden>
- Date: Wed, 15 Jan 2003 15:34:04 -0500
I always have to find the strange ones...
this has to do with including headers. i had two classes that both
knew about each other,
and both included each other's headers. I had to also add @class Warp;
moral of story:
this is always a mistake.
second moral:
the gcc compiler is weird.
a method to map a value from 0..1 to a range (in this case 20..20000
exponential).
spec:
-(float)map:(float)value
{
return (float)[warp map: value];
}
warp:
#include "math.h"
-(float)map:(float)value
{
return pow([spec ratio] , value) * [spec minval];
}
problem:
doing a simple unit test of this, it works as expected. but when put
into the app and sending the
value from a slider, it fails. instead of returning the mapped value,
it returns something else.
add some debugging code to spec:
spec:
-(float)map:(float)value
{
NSLog(@"min:%f max:%f ratio:%f inval: %f calculated:%f warp
returns:%f",minval,maxval,value,[self ratio],
pow([self ratio] , value) * [self minval],[warp map: value]);
return (float)[warp map: value];
}
min:20.000000 max:20000.000000 ratio: 1000.000000 inval: 0.852941
calculated:7241.915648
warp returns:0.762353
When i do the calculation here in this method, I get the correct
answer, but when warp is called to do the same calculation,
it returns something else.
Now it gets strange:
add some debugging code to warp:
warp:
#include "math.h"
-(float)map:(float)value
{
NSLog(@"Warp::map inval:%f spec ratio: %f spec minval: %f pow:
%f",value,[spec ratio],[spec minval],pow([spec ratio] , value));
return pow([spec ratio] , value) * [spec minval];
}
BY ADDING THIS NSLOG, WARP NOW RETURNS A DIFFERENT ANSWER ???
min:20.000000 max:20000.000000 ratio: 1000.000000 inval: 0.907563
calculated:10561.341551
warp returns:1055.139648
comment it out, I get some 0..1 value.
uncomment it, I get this different higher number.
fascinating.
i see that i also had in Spec.m :
#import "Warp.h"
i comment this out.
now i get yet a different answer. still not the correct one.
so i factored it out so Warp doesn't need to know about the internals
of Spec and doesn't need to read its headers.
and it all works.
i really wish there was a preprocessor system that would take care of
all
header generation, smart inclusions. and throw in auto-completion,
real time
type checking, method lookup...
but still generate objective-c code.
-felix
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.