[cfe-dev] Rewrite Objective-C to C

Dado Colussi dado.colussi at gmail.com
Mon Nov 10 07:53:23 PST 2008


On Nov 10, 2008, at 4:21, Nico Weber wrote:

> Hi Dado,
>
> On 10.11.2008, at 06:41, Dado Colussi wrote:
>
>> I am interested in trying to use clang to convert Objective-C code to
>> C, and compiling the generated C code with 3rd party compiler. I have
>> managed to convert and compile a very simple hello application on my
>> Mac using Apple's runtime after having tweaked the generated code. I
>> have failed with anything more complex than the hello in one file.
>>
>> I wonder:
>> * How realistic and feasible my approach is?
>> * How mature the rewrite code in clang is?
>> * Is there enough community interest to actually make the rewrite  
>> code
>> complete?
>
> did you use `clang -rewrite-objc` to do the rewriting? Can you give  
> an example of a problem you encountered?
>
> Nico


Hi Nico,

I executed the following commands:

clang -rewrite-objc Hello.m
g++ -o Hello Hello.cpp -lobjc

First I got errors about missing types, such as id. When I added  
#import <objc/objc-runtime.h>, I got type conflicts. After I removed  
all generated code until my first #import, Hello.cpp compiled OK.

I also noticed that if I #import a header file (.h) in Objective-C  
code, the same file is #included in the generated C code. When the  
file contains Objective-C syntax, the C compiler barfs.

/Dado

---
#import <objc/objc-runtime.h>
#import <stdio.h>

@interface Hello
{
}
+ (void)initialize;
+ (void)sayHello;
@end

@implementation Hello

+ (void)initialize
{
}

+ (void)sayHello
{
	printf("Hello, World!\n");
}

@end

int
main()
{
	[Hello sayHello];
}






More information about the cfe-dev mailing list