2011-06-29 8 views
0
#import <Foundation/NSArray.h> 
#import <Foundation/NSString.h> 
#import <Foundation/NSAutoreleasePool.h> 
#import <Foundation/NSEnumerator.h> 
#import <stdio.h> 

void print(NSArray *array) { 
NSEnumerator *enumerator = [array objectEnumerator]; 
id obj; 

while (obj = [enumerator nextObject]) { 
    printf("%s\n", [[obj description] cString]); 
} 
} 

int main(int argc, const char *argv[]) { 
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
NSArray *arr = [[NSArray alloc] initWithObjects: 
       @"Me", @"Myself", @"I", nil]; 
NSMutableArray *mutable = [[NSMutableArray alloc] init]; 

// enumerate over items 
printf("----static array\n"); 
print(arr); 

// add stuff 
[mutable addObject: @"One"]; 
[mutable addObject: @"Two"]; 
[mutable addObjectsFromArray: arr]; 
[mutable addObject: @"Three"]; 

// print em 
printf("----mutable array\n"); 
print(mutable); 

// sort then print 
printf("----sorted mutable array\n"); 
[mutable sortUsingSelector: @selector(caseInsensitiveCompare:)]; 
print(mutable); 

// free memory 
[arr release]; 
[mutable release]; 
[pool release]; 

return 0; 
} 

このプログラムは、Windowsでoscv0.1.4でコンパイルされています。目的のCの解析エラー

Error: Parse error on line 6: 
...import <stdio.h> 

void print(NSArray 
---------------------^ 
Expecting 'INTERFACE', 'IMPLEMENTATION', 'PROTOCOL', 'IMPORT', 'CLASS', 'DEFINE', 'EOF' 

次のように それは今では、以下に示すプログラムのための1つ以上のエラーが発生しました(それは別のプログラムである)

#import "Forwarder.h" 
#import "Recipient.h" 

int main(void) 
{ 
    Forwarder *forwarder = [Forwarder new]; 
    Recipient *recipient = [Recipient new]; 

[forwarder setRecipient:recipient]; //Set the recipient. 
[forwarder hello]; 

[recipient release]; 
[forwarder release]; 

return 0; 
} 

エラーが

Error: Parse error on line 3: 
...Recipient : Object 
- (id)hello; 
@end#i 
----------------------^ 
Expecting '<', '{' 
+1

私はoscvのことを聞いたことがありません。 GCCのような別のコンパイラを試してみましたか? oscvには、前処理されたソースファイル(GCCの '-E'オプションに相当)を表示するオプションがありますか? –

+0

このリンクをクリックhttp://code.google.com/p/oscompiler/downloads/list –

+0

このコンパイラで別のプログラムをコンパイルして実行します。これは問題ありません。 –

答えて

1

フォーマットでエラーを返しますあなたのプログラムのコードは以下のようにしなければなりません メインはメインクラスを含める必要があります これをリンクと比較してください http://code.google.com/p/oscompiler/downloads/list

@interface Main : NSObject { } 
@end 

@implementation Main 
+(void)main { 
NSLog(@"Hello world!"); 
} 
@end 
関連する問題