Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sharing c++ class



On Nov 29, 2003, at 3:28 PM, Alexander Cohen wrote:

So that would be the only way. Its not possible to have a library that exports a C++ class?

You can have a library that exports the C++ class but there are significant caveats which may make it not worth doing.

If your class implements (or is likely to add) virtual methods then changes to the C++ ABI (Application Binary Interface) standard as output by the compiler and shipped/used with your library will mean that you have to be very careful about ABI Changes with each compiler version. Also if you add virtual methods to your base classes this will potentially require anyone inheriting from those classes to rebuild their application or you take great care to provide sufficient 'padding' in the vtable of your base classes so that you can add new virtuals without so many problems.

gcc has regularly changed the ABI for C++ between compiler revisions which means that you'd need to supply and potentially maintain different libraries for each compiler version, furthermore your 'customers' will need to know what version of the compiler they have and use the appropriate library.

The Framework mechanism may be some help here but at the bottom of it all you have to be very aware of what's going on 'outside' of your code.

In the long run as others mentioned it may just be best to hide your C++ class behind a C interface API since you'll avoid the compiler problems (or use Objective-C which doesn't suffer from the same fragility 8-).

Andrew 8-)
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: sharing c++ class (From: Tom Becker <email@hidden>)
 >Re: sharing c++ class (From: Alexander Cohen <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.