Re: ObjC++ and .mm vs .cpp
Re: ObjC++ and .mm vs .cpp
- Subject: Re: ObjC++ and .mm vs .cpp
- From: Steve Checkoway <email@hidden>
- Date: Wed, 7 Sep 2005 03:20:38 -0700
On Sep 7, 2005, at 2:40 AM, Markus Hitter wrote:
Am 06.09.2005 um 19:42 schrieb Peter.Teeson:
Having read all I can find about Objective-C++ I still have a
question and it's this:
In my project can I have source files with the .cpp extension as
well as .mm?
Yes. You can link objects compiled with any of the gcc compilers
together. For some combinations you need hints like
extern C {
// some C code
}
Generally, this would go around function declarations. See below.
IOW can I keep my C++ model files with the .cpp extension or MUST
they all be .mm?
You want the .mm extension if the source contains Obj-C as well as C
++. Keep the .c extension for plain C files, .cpp for pure C++
and .m for pure Obj-C. This speeds up your compilations and keeps
your language separation tidy.
If you have header files that are to be included by both Obj-C and C+
+ (or Obj-C++), you can wrap the function declarations as follows:
in foobar.h:
#ifndef FOOBAR_H
#define FOOBAR_H
#ifdef __cplusplus
extern "C" {
#endif
/* Put function declarations in here. E.g. */
void foo();
int bar(float f);
#ifdef __cplusplus
}
#endif
#endif /* FOOBAR_H */
Another way, is to #include <sys/cdefs.h> in the header file and use
__BEGIN_DECLS and __END_DECLS:
#ifndef FOOBAR_H
#define FOOBAR_H
#include <sys/cdefs.h>
__BEGIN_DECLS
void foo();
int bar(float f);
__END_DECLS
#endif /* FOOBAR_H */
- Steve
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden