Hi,
It would be great if someone would kindly tell me what I'm doing wrong.

Something like the much simplified code below used to work under Tiger in 10.4 running on antique 400 MHz G4. The idea is that the program passes the id of an anonTargetClassObject to a calling object which then sends a message to that anonTargetClassObject id. What seems to be happening is that I am not getting the compiler to generate the correct type information for the float and unsigned char message parameter.
The code is implemented in Leopard running on a mac Pro.

In the build info I have
Instruction scheduling = PowerPC G5 - I've tried several of the options without success
Objective-C Garbage Collection = Required
Optimisation Level = Fastest, smallest

C language dialect = Compiler Default
Compile Sources as = Objective-C

Everything else is set to the default.

I'm sure I'm giving you more code than you need but here goes ....
=======================
//the .h and .m files of object to which the message is sent

#import <Cocoa/Cocoa.h>
@interface AnonTargetClass : NSObject {
}
- (void) printSimple;
- (void) printString:(NSString *)pS;
- (void) printFloat:(float)pF;
- (void) printInt:(int)pI;
- (void) printUnsignedChar:(unsigned char)pC;
- (void) printUnsignedCharRef:(unsigned char *)pC;
@end

#import "AnonTargetClass.h"
@implementation AnonTargetClass
- (void) printSimple;
{
        NSLog(@"AnonTargetClass printSimple =Hi from AnonTarget");
}

- (void) printString:(NSString *)pS;
{
        NSLog(@"AnonTargetClass printString = %@",pS);
}

- (void) printFloat:(float)pF;
{
        NSLog(@"AnonTargetClass printFloat = %7.3f",pF);
}

- (void) printInt:(int)pI;
{
        NSLog(@"AnonTargetClass printInt = %6d",pI);
}

- (void) printUnsignedChar:(unsigned char)pC;
{
        NSLog(@"AnonTargetClass printUnsignedChar = %6d",pC);
}

- (void) printUnsignedCharRef:(unsigned char *)pC
{
        NSLog(@"AnonTargetClass printUnsignedCharRef = %6d",*pC);
}

@end


//the .h and .m files of calling object
#import <Cocoa/Cocoa.h>
@interface CallingClass : NSObject {    
}
- (void) callPrintSimple:(id)pId;
- (void) callPrintConstString:(id)pId;
- (void) callPrint:(id)pId zString:(NSString *)pS;
- (void) callPrintConstFloat:(id)pId;
- (void) callPrint:(id)pId zFloat:(float)pF;
- (void) callPrintConstInt:(id)pId;
- (void) callPrint:(id)pId zInt:(int)pI;
- (void) callPrintConstUnsignedChar:(id)pId;
- (void) callPrint:(id)pId zUnsignedChar:(unsigned char)pI;
- (void) callPrintConstUnsignedCharRef:(id)pId;
- (void) callPrint:(id)pId zUnsignedCharRef:(unsigned char *)pI;

@end

#import "CallingClass.h"
@implementation CallingClass
- (void) callPrintSimple:(id)pId
{
        [pId printSimple];
}

- (void) callPrintConstString:(id)pId
{
        [pId printString:@"Hi from PrintConstString"];
}

- (void) callPrint:(id)pId zString:(NSString *)pS
{
        [pId printString:pS];
}

- (void) callPrintConstFloat:(id)pId
{
        [pId printFloat:12.34];
}

- (void) callPrint:(id)pId zFloat:(float)pF
{
        [pId printFloat:pF];
}

- (void) callPrintConstInt:(id)pId
{
        [pId printInt:5];
}

- (void) callPrint:(id)pId zInt:(int)pI
{
        [pId printInt:pI];
}

- (void) callPrintConstUnsignedChar:(id)pId;
{
        [pId printUnsignedChar:222];
}

- (void) callPrint:(id)pId zUnsignedChar:(unsigned char)pCh;
{
        [pId printUnsignedChar:pCh];
}

- (void) callPrintConstUnsignedCharRef:(id)pId;
{
        unsigned char * tvarUnsignedChar        = 123;
        [pId printUnsignedCharRef:&tvarUnsignedChar];
}

- (void) callPrint:(id)pId zUnsignedCharRef:(unsigned char *)pChRef;
{
        [pId printUnsignedCharRef:pChRef];
}

@end


// main.m
#import <Cocoa/Cocoa.h>
#import "AnonTargetClass.h"
#import "CallingClass.h"

int main(int argc, char *argv[])
{
        AnonTargetClass * anonObjToBeCalled     = [[AnonTargetClass alloc]init];
        CallingClass    * callingObj            = [[CallingClass alloc]init];
        
        float tvarFloat = 6.54;
        int tvarInt     = 321;
        unsigned char tvarUnsignedChar= 255;
        NSLog(@"Check the methods of AnonTargetClass");
        [anonObjToBeCalled printSimple];
        [anonObjToBeCalled printString:@"String direct from main"];
        [anonObjToBeCalled printFloat:98.76];
        [anonObjToBeCalled printFloat:tvarFloat];
        [anonObjToBeCalled printInt:55];
        [anonObjToBeCalled printInt:tvarInt];
        [anonObjToBeCalled printUnsignedChar:tvarUnsignedChar];
        [anonObjToBeCalled printUnsignedCharRef:&tvarUnsignedChar];
        NSLog(@"End checking methods of AnonTargetClass");
        
        NSLog(@"calling the methods dynamically");
        [callingObj callPrintSimple:                            
(id)anonObjToBeCalled ];
        [callingObj callPrintConstString:                       
(id)anonObjToBeCalled];
        // just testing the lack of coersion
[callingObj callPrint: anonObjToBeCalled zString:@"This string passed from main 1"]; [callingObj callPrint: (id)anonObjToBeCalled zString:@"This string passed from main 2"];
        [callingObj callPrintConstFloat:                        
(id)anonObjToBeCalled];
        [callingObj callPrint:                                          
(id)anonObjToBeCalled zFloat:56.78];
        [callingObj callPrintConstInt:                          
(id)anonObjToBeCalled];
        [callingObj callPrint:                                          
(id)anonObjToBeCalled zInt:9];
        [callingObj callPrintConstUnsignedChar:         (id)anonObjToBeCalled];
        [callingObj callPrint:                                          
(id)anonObjToBeCalled zUnsignedChar:111];
        [callingObj callPrintConstUnsignedCharRef:      (id)anonObjToBeCalled];
[callingObj callPrint: (id)anonObjToBeCalled zUnsignedCharRef:&tvarUnsignedChar];
        NSLog(@"End calling the methods dynamically");

    return 0;
}


// The output is as follows - I have removed the date/time info and marked the incorrect values with asterisks

[Session started at 2008-05-15 02:10:16 +0100.]
2008-05-15 02:10:16.665 testDynamicBinding[1311:10b] Check the methods of AnonTargetClass 2008-05-15 02:10:16.666 testDynamicBinding[1311:10b] AnonTargetClass printSimple =Hi from AnonTarget 2008-05-15 02:10:16.666 testDynamicBinding[1311:10b] AnonTargetClass printString = String direct from main 2008-05-15 02:10:16.667 testDynamicBinding[1311:10b] AnonTargetClass printFloat = 98.760 2008-05-15 02:10:16.667 testDynamicBinding[1311:10b] AnonTargetClass printFloat = 6.540 2008-05-15 02:10:16.667 testDynamicBinding[1311:10b] AnonTargetClass printInt = 55 2008-05-15 02:10:16.668 testDynamicBinding[1311:10b] AnonTargetClass printInt = 321 2008-05-15 02:10:16.668 testDynamicBinding[1311:10b] AnonTargetClass printUnsignedChar = 255 2008-05-15 02:10:16.668 testDynamicBinding[1311:10b] AnonTargetClass printUnsignedCharRef = 255 2008-05-15 02:10:16.669 testDynamicBinding[1311:10b] End checking methods of AnonTargetClass 2008-05-15 02:10:16.669 testDynamicBinding[1311:10b] calling the methods dynamically 2008-05-15 02:10:16.669 testDynamicBinding[1311:10b] AnonTargetClass printSimple =Hi from AnonTarget 2008-05-15 02:10:16.669 testDynamicBinding[1311:10b] AnonTargetClass printString = Hi from PrintConstString 2008-05-15 02:10:16.670 testDynamicBinding[1311:10b] AnonTargetClass printString = This string passed from main 1 2008-05-15 02:10:16.670 testDynamicBinding[1311:10b] AnonTargetClass printString = This string passed from main 2 2008-05-15 02:10:16.670 testDynamicBinding[1311:10b] AnonTargetClass printFloat = 584860314976236483507101602781593600.000 ****** 2008-05-15 02:10:16.671 testDynamicBinding[1311:10b] AnonTargetClass printFloat = 0.000 ****** 2008-05-15 02:10:16.671 testDynamicBinding[1311:10b] AnonTargetClass printInt = 5 2008-05-15 02:10:16.671 testDynamicBinding[1311:10b] AnonTargetClass printInt = 9 2008-05-15 02:10:16.671 testDynamicBinding[1311:10b] AnonTargetClass printUnsignedChar = 222 2008-05-15 02:10:16.672 testDynamicBinding[1311:10b] AnonTargetClass printUnsignedChar = 111 2008-05-15 02:10:16.672 testDynamicBinding[1311:10b] AnonTargetClass printUnsignedCharRef = 123 2008-05-15 02:10:16.672 testDynamicBinding[1311:10b] AnonTargetClass printUnsignedCharRef = 255 2008-05-15 02:10:16.673 testDynamicBinding[1311:10b] End calling the methods dynamically


Thanks
Julius

http://juliuspaintings.co.uk



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to