# C++ Programming on a Mac



## milhaus (Jun 1, 2004)

Have an engineering student wondering about buying a Mac; how's C++ programming on the platform?
Anyone know?


----------



## mikef (Jun 24, 2003)

Hopefully as good as C or ObjC programming... OS X comes with g++ and Xcode can create C++ projects.

Obviously the desirable language for Cocoa development is ObjC.


----------



## jamesm (Jun 7, 2005)

What kind of software are you going to write? School programming assignments or something more ambitious? 

I'm just finishing my masters having written some network simulation software in c++ on my powerbook. I've stuck to the gnu toolchain for cross-platform reasons (macosx, linux, windows+cygwin) so I can't really comment on xcode c++ integration. I can check xcode out and report back if you have something specific in mind. Also, I believe macosx device drivers are developed using c++.

Cheers.


----------



## mikef (Jun 24, 2003)

jamesm said:


> Also, I believe macosx device drivers are developed using c++.


Maybe they can be, but I would assume that almost all drivers are written in C, the same language the kernel is written in.


----------



## green_ears (Feb 26, 2005)

milhaus said:


> Have an engineering student wondering about buying a Mac; how's C++ programming on the platform?
> Anyone know?


C/C++ coding is the same as on any *NIX machine. You get all the GNU compilers and libraries by default if you open up the terminal. You get make and all the other tools too. I use the CDE for Eclipse and it works great! Just beware when importing the code into MS Visual Studio on the MS Windows platform... MS just isn't standard ANSI C. My code behaved completely differently than on *NIX platforms or Cygwin. =)


----------



## mikef (Jun 24, 2003)

green_ears said:


> MS just isn't standard ANSI C. My code behaved completely differently than on *NIX platforms or Cygwin. =)


That's not quite correct. Both Windows and gcc both support ANSI C, however there are obvious C runtime differences. The plain language (ie. printf, for, while, etc) code behaves identically across all ANSI C implementations.

For most C programming courses, the same source code will compile and run anywhere. When you start using platform specific things (ie. UI/GUI, network I/O, etc), code portability breaks.


----------



## Trose (Feb 17, 2005)

Haha, coincidence or what? Just yesterday I was looking for information about C++ and Macs... and I'm an engineering student...  Thanks for the information!


----------



## jamesm (Jun 7, 2005)

mikef said:


> Maybe they can be, but I would assume that almost all drivers are written in C, the same language the kernel is written in.


You're right of course. Code that runs in kernel space is C (e.g. KEXTs). However, apple provides the IOKit which is a some kind of subset of C++. The IOKit, I believe, basically exposes most hardware devices to user space. You can just take the appropriate IOKit class and implement the required methods for your device.

Cheers.


----------



## mikef (Jun 24, 2003)

Very interesting! I was not aware of the IOKit abstraction. Here's a brief overview for those interested:

http://developer.apple.com/devicedrivers/overview.html

More specifically about I/O Kit:

http://developer.apple.com/document..._section_1.html#//apple_ref/doc/uid/TP0000012

Thanks for the pointers. I've worked on device drivers on Windows and Linux in the past but not OS X.


----------

