-rewrite-objc and Objective-C in clang
Asked Answered
E

1

2

Recently, I have one problem. The clang can translate Objective-C to c++ use -rewrite-objc. So I think, the first step. clang compile Objective-C to C++. And then compile only can use c++ compiler. Is it do like this? clang first translate Objective-C to C++ with runTime, and then compile to the machine code?

Emmi answered 15/6, 2017 at 7:28 Comment(0)
E
5

-rewrite-objc exists to translate ObjC to C++ so it can be compiled in the Visual Studio. It is still Objective-C semantics and you still need the objective-c runtime. It is not magically converting Objective-C to the C++ OO architecture.

This is much more like when Objective-C was implemented as a pre-compiler extension.

It all relies on the fact that Objective-C classes are just C structures with fancy behavior and objective-c method calls all can be translated to calls to objc_msgSend().

Enameling answered 24/6, 2017 at 17:42 Comment(4)
Thank you. But I also what to know, dose Clang translate OC to machine code directly instead of to C++ first when compiling?Brickle
It translates it to C++ code (mostly C, really) before compilation; specifically, before the visual studio compiler takes over, typically.Enameling
sorry for disturb you. In this question, the top answer confuse me. So dose any C/C++ IR live when compiling OC?Brickle
@Brickle Totally different situation; that question is talking about compiling code to IR. This question is referring to the ObjC rewriter. The goal of the rewriter is to spit straight C/C++ code that can be compiled by another compiler -- typically the Visual C++ compiler in Visual Studio.Enameling

© 2022 - 2024 — McMap. All rights reserved.