Skip navigation.
 
mlRe: programming in C++ ?
FROM : Jay Reynolds Freeman
DATE : Thu Jan 31 19:20:08 2008

On the general topic of mixing Cocoa/Objective-C and C++, I might 
knock on wood and report a modest success story:

I have an application -- a Scheme-programming-language interpreter 
(Wraith Scheme) -- designed in the model/view/controller pattern. 
The model is essentially all straight C++ -- all ".c++" files and 
associated headers -- and when I use it in a standard Macintosh 
application, it runs in its own thread.  The view and controller are 
in that case mostly Objective-C, with occasional references to things 
to get the model's thread going and keep in touch with it; they use 
all either ".m" or ".mm" files, with associated headers, and with 
lots of Cocoa calls.

I set the application up this way because I originally got the 
application going with the model running with two additional, 
different, view/controller combinations:  The same C++ code for the 
model can run with a straight Unix-shell view/controller -- as a text-
oriented line-at-a-time process in a "Terminal" window -- or with an 
"ncurses" view/controller, also running in a Terminal window.  I 
followed that development path to port the program to Tiger from a 
much older Mac application, dating from pre-Carbon Mac-Toolbox days. 
I was a newcomer to Cocoa at the time of the port, so I did it that 
way in order to deal with upgrading the model separately from coming 
up to speed on Cocoa.  I use #ifdefs on symbols defined by compile-
time flags to control which build to create and to control how the 
model communicates with its view/controller -- the Cocoa version is 
built with XCode (2.4.1, on Tiger), the Unix versions with 
conventional make files.  There are also, of course, different source 
files used for the different view/controller combinations.

This mix of languages, libraries, and build mechanisms has worked 
seamlessly so far (and this is where I knocked on wood).  My suite of 
regression tests automatically builds and tests all of these 
versions, and there have been few maintenance problems associated 
with the differences between them.  I suspect (another knock on wood) 
that it would be straightforward to adapt the Unix versions of the 
application to (heresy!) other Unix versions and other hardware 
platforms.

--  Jay Reynolds Freeman
---------------------
<email_removed>
http://web.mac.com/jay_reynolds_freeman (personal web site)

Related mailsAuthorDate
mlRe: programming in C++ ? John Stiles Jan 30, 16:22
mlprogramming in C++ ? Cor Jan 31, 00:17
mlRe: programming in C++ ? Vance Jan 31, 00:42
mlRe: programming in C++ ? Uli Kusterer Jan 31, 00:53
mlRe: programming in C++ ? John Stiles Jan 31, 01:00
mlRe: programming in C++ ? Thomas Engelmeier Jan 31, 09:22
mlRe: programming in C++ ? Jiva DeVoe Jan 31, 16:17
mlRe: programming in C++ ? Shawn Erickson Jan 31, 17:39
mlRe: programming in C++ ? Shawn Erickson Jan 31, 17:40
mlRe: programming in C++ ? John Stiles Jan 31, 18:25
mlRe: programming in C++ ? Kevin Elliott Jan 31, 19:17
mlRe: programming in C++ ? Jay Reynolds Freem… Jan 31, 19:20
mlRe: programming in C++ ? Thomas Engelmeier Feb 1, 12:13
mlRe: programming in C++ ? John Stiles Feb 1, 18:35
mlRe: programming in C++ ? Thomas Engelmeier Feb 3, 17:44
ml[OT] Re: programming in C++ ? Alastair Houghton Feb 3, 19:16