C++ and Mac

Discussion in 'Mac Programming' started by coastertux, May 30, 2007.

  1. coastertux macrumors regular

    Joined:
    Jul 17, 2006
    #1
    I am taking a C++ programming course at my university in the Fall but it is geared towards Windows programming. How easy will it be for me to transfer my knowledge to programming on Macs? Where can I find more info on this?
     
  2. slooksterPSV macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
    #2
    C++ is the same on Mac as it is on PC, THe only thing you'll have to watch out for is having certain header files or that. Now as for API difference, with Windows you'll mainly have to program a lot of it in unless you use a GUI builder, whereas with Mac's its all builtin and no immediate linking is needed. I've programmed WinAPI on PC and have built apps on mac os x, Mac's are sincerely easier, but if you have the help of a GUI builder then you'll be fine, the transition will be different cause you'll have DWORDs etc. and tha tand won't have the common use of NSObject as being yoru main Object which really sucks in the long run. I think it won't be that bad, but it won't be extremely easy either.
     
  3. garethlewis2 macrumors 6502

    Joined:
    Dec 6, 2006
    #3
    Uhh no. C++ on the Mac is not like C++ for Windows, unless you are doing the most basic of C++ programs that use a terminal for input and output. If the OP is doing actual VC++ work, then they are not using a C++ compiler, but a Microsoft C++ compiler which is different. Next if they are having to build forms, then you can forget about making the code cross-platform. It would be the same as loading up Objc-C in VC++ and trying to compile that.
     
  4. MacDonaldsd macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #4
    C++ in terms of syntax etc is the same on all OSs.

    The differences come when you have to access external files etc.
     
  5. garethlewis2 macrumors 6502

    Joined:
    Dec 6, 2006
    #5
    Uhh, no.

    Microsoft Visual C++ is not Ansi C++. They have made that obvious from the start. It doesn't handle the standard libraries except in VC++ 2005 in a normal fashion. VC++ was designed to build Windows applications, not as a C++ compiler.
     
  6. hawaiian macrumors member

    hawaiian

    #6
    The same style of thinking that you use in order to make certain programs with windows should apply to other programming languages and other platforms. What's usually new is the language grammar and the API. For example, some languages do not use loops, and rely completely on recursion. So to answer your question, you should be able to transfer your knowledge of program design, but you may have to learn a new API.

    Hope this answers your question.
     
  7. Torajima macrumors regular

    Joined:
    Jan 6, 2004
    Location:
    USA
    #7
    If you're taking an intro to c++ course, it doesn't matter what you write the code on, Mac, Windows, or Linux. You can try the program on the Mac by compiling in Xcode, and then take the source code to class and compile again with whatever compiler they're using in windows.

    The programs should run exactly the same, at least until you take a more advanced course involving graphic user interfaces.
     
  8. slooksterPSV macrumors 68030

    slooksterPSV

    Joined:
    Apr 17, 2004
    Location:
    Nowheresville
    #8
    MVC++ is not Ansi C++ true, but C++ syntax is the same on all OSes MVC++ is not C++, C++ is C++, MVC++ is MVC++, that's my personal opinion.

    Just lay down the basics, try not to confuse the poor guy, we could get into versions of C++ Compilers? GCC, Microsoft, Borland, etc. Just kidding =P lets not seriously
     
  9. Columbo X macrumors member

    Joined:
    Jun 10, 2007
    Location:
    UK
    #9
    Programming knowledge is fairly transferable, as has been said above. It's largely the differences in APIs or syntax that can cause problems.

    If you're going to port code between the two platforms, one thing I would advise is you check out the Model-View-Controller design pattern when thinking about your code design. I first came across this when looking at Cocoa development when OS X 10.0 first came out. Apple have a load of documentation about this on their developer web pages. The nice thing about orgainising your code around this structure is that non-OS / API specific stuff can be ported directly with no/minimal changes. The OS / API specific stuff can then be implemented as required. For instance, I'm currently porting a lot of Win32 code to Cocoa. In developing the Windows code, I stuck to the Model-View-Controller structure. I've written the Windows code so the Windows-specific WinMain and WndProc event handler make up the controller / view side and the rest of the code (classes for first person cameras, fractal landscapes etc) are written using C++ without any need for Microsoft-specific stuff.

    Porting is then quite straightforward. X-Code and Interface Builder make it easy to create the relevant interfaces and the C++ stuff can be ported across with minimal changes (usually only include statements have to be changed). On the Mac side of things, Objective-C++ is very useful and makes this process far easier as your C++ classes can be linked directly to the Cocoa interface.
     

Share This Page