I have an Objective C project with some C++ code, and sure enough the C++ code won't compile
I understand that the compiler makes assumptions about which language to compile, but I have seen this app running before so I am curious how to make my Xcode 4 run compile this project
ie. This function declaration produces an error as the compiler does not recognize the c++ std::
syntax
std::string string_with_formatting(const unsigned int value)
{
How do I get around this? What #include or #import should I have
Compiling Objective-C into C doesn't make sense, because then it would need to parse the C code and compile it. Objective-C compiles into machine code. Remember that the language (Objective-C, C, C++) only defines the rules to correctly write code.
The best platform for developing Objective‑C is Mac OS. But Objective‑C programs can also be compiled and run on Windows or Linux by using GNUstep and an Objective‑C compiler.
These days, Xcode ships with clang as the compiler. Wherever we write compiler, you can read it as clang. clang is the tool that takes Objective-C code, analyzes it, and transforms it into a more low-level representation that resembles assembly code: LLVM Intermediate Representation.
Objective-C is slightly slower than straight C function calls because of the lookups involved in its dynamic nature.
Objective-C++ is a superset of C++. You can use C++ in Objective-C++ sources.
.mm
extension, otherwise it will be treated as Obj-C, not Obj-C++#include <string>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With