• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ObjC++ and .mm vs .cpp
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >ObjC++ and .mm vs .cpp (From: "Peter.Teeson" <email@hidden>)
 >Re: ObjC++ and .mm vs .cpp (From: Markus Hitter <email@hidden>)

  • Prev by Date: Re: ObjC++ and .mm vs .cpp
  • Next by Date: JarBundler and Java 5
  • Previous by thread: Re: ObjC++ and .mm vs .cpp
  • Next by thread: Problems bundleizing a static library in Development Build Style
  • Index(es):
    • Date
    • Thread