# Windows vs. Mac Programming!

## Recommended Posts

Howdy! I am currently learning C++ on my winXP desktop, and am in a hard decision right now. Well, im thinking of buying a mac laptop. 1. The thing is, whats the difference, programming wise between windows XP and mac? 2. How do i create things that would work with both winXP and mac? do i have to create 2 diff projects, or can the same code work on both machines, such as creating a window and stuff like that? 3. After its all said and programmed (haha), would it better for me to stick with windows, or would it be the samething if i get a mac? Any help is greatly appreciated!

##### Share on other sites
You and I, we are only seconds apart with a very similar question! [smile]

Might I add, I beat you by 22 seconds [razz]

##### Share on other sites
As long as you avoid platform-specific calls such as those in windows.h, your code should be cross-platform already. Things like creating a window can be done in SDL and be cross-platform, or you can use platform-specific API calls for each platform and wrap them in
#ifdef __WIN32
#endif
#ifdef __APPLE__
#endif

OpenGL can be used on MacOS and Windows, but stay away from DirectX if you want your code to run on a Mac.

##### Share on other sites
Quote:
 Original post by v0dKAYou and I, we are only seconds apart with a very similar question! [smile]Might I add, I beat you by 22 seconds [razz]

Damn you! I bet you were watching me outside my window and ran home to post it, just to make me look dumb! [lol]

Quote:
 Original post by Driv3MeFar As long as you avoid platform-specific calls such as those in windows.h, your code should be cross-platform already. Things like creating a window can be done in SDL and be cross-platform, or you can use platform-specific API calls for each platform and wrap them in#ifdef __WIN32#endif#ifef __APPLE__#endifOpenGL can be used on MacOS and Windows, but stay away from DirectX if you want your code to run on a Mac.

Thanks for the help.

Also, would system("pause") or system("cls") still work for macs as well?

##### Share on other sites
Quote:
 Original post by NUCLEAR RABBITAlso, would system("pause") or system("cls") still work for macs as well?

No. Those are Windows-specific. Macintosh has standard Unix commands. But you probably shouldn't be using the pause command anyway.

##### Share on other sites
System() commands will only work on Windows

##### Share on other sites
Might I add, I doubt WinMain() will be WinMain() on a Mac. WinMain(), as you may not know yet, is the application entry point of a Windows program.

I'm not sure what the application entry point would be on other operating systems. UnixMain()? MacintoshMain?

Console programs, however, might have the same entry point main(). But then again, they might not. I never tried programming on different platforms yet.

But anyways, as I mentioned in my own thread, the wxWidgets library is made for the sake of cross-platform portability. But as CoyCash pointed out, the code must be compiled on the actual operating system in order to run on it. Which, if you're developing applications for other people, kind of sucks... . But at least you won't have to change the actual code for each operating system.

I think, other than wxWidgets, you can use SDL for portability. But I haven't used SDL, so again I'm not sure.

Hopefully, now that I've thrown these ideas out here, someone who knows can verify.

##### Share on other sites
Quote:
 Original post by CoyCashSystem() commands will only work on Windows

nonsense!

:~\$ cat foo.cpp && ./foo#include <cstdlib>int main(int, char**) {        system("cat /proc/version");        return 0;}Linux version 2.6.15-26-386 (buildd@terranova) (gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu5)) #1 PREEMPT Thu Aug 3 02:52:00 UTC 2006

of course "commands" vary from os to os.

##### Share on other sites
Quote:
 Original post by v0dKAMight I add, I doubt WinMain() will be WinMain() on a Mac. WinMain(), as you may not know yet, is the application entry point of a Windows program.I'm not sure what the application entry point would be on other operating systems. UnixMain()? MacintoshMain?

Just main.

##### Share on other sites
Quote:
 Original post by NUCLEAR RABBITHowdy!I am currently learning C++ on my winXP desktop, and am in a hard decision right now. Well, im thinking of buying a mac laptop. 1. The thing is, whats the difference, programming wise between windows XP and mac?2. How do i create things that would work with both winXP and mac? do i have to create 2 diff projects, or can the same code work on both machines, such as creating a window and stuff like that?3. After its all said and programmed (haha), would it better for me to stick with windows, or would it be the samething if i get a mac?Any help is greatly appreciated!

OK, having purchased a Mac to learn how to develop for it, and this is from a beginner Mac person, so don't hold this sacred (that you do for the people at idevgames.com).

1) Cocoa vs Carbon. You can create C++ tools, but if you want graphics, or your typical window, you'll have to choose one of the frameworks. Carbon is C, Cocoa is Objective C. I've only started using Obj C, so I'm hardly an expert. Certain things are nicer about it, certain things confuse me.

1.5 XCode vs Visual Studio. Well, you do have alternative IDE's & Compilers, but these are the big 2 on the machines. And I'll be blunt here. As much as people give Microsoft grief, Visual Studio is second to none when it comes to development. On the other hand, XCode is free (I can't state anything about the Express Edition of VS, I own a full version, so I don't know how handicapped the EE is). And I find the XCode debugger really isn't that great.

2) Use cross platform libraries. Even with this being said, what you create may not necessarily work right off the bat. There are places where I have to put #ifdef __APPLE_CC__ & #ifdef _MSC_VER

3) Depends what you're after. If you want to learn a new system, getting a Mac can be a great experience. Programs work sort of differently (ie: one instance vs multiple instances). And with bootcamp, you can get Windows on there, so worse comes to worse, you don't lose anything. As for employment opportunities, I really can't help you there. Most likely the windows world is the way to go.

##### Share on other sites
So, inorder for the program to work for diff platforms (win, mac, linix), i need to compile the program on each OS?

Also, im pretty sure im going to be learning OpenGL pretty soon (maybe in a month), and if i program on a mac, all i need to do make it work for windows, is save to a memory stick, upload on my desktop, and compile the code on winXP, and not have to change 500 lines of coding?

The reason i ask, is that im pretty sure im going to probably get a macbook. [smile]

@ Nytegard:

Im not looking for work in the apple business, im just looking for a laptop to use for music, internet, and program on. Im going to want to program games on it, but i want to make sure that before i buy a mac, that i wont have to learn a lot of new stuff, just to be where i am at right now programming on windows even though i havent learned any graphix API's yet.

##### Share on other sites
SDL, OpenGL and OpenAL is the way to go. Feels much nicer than DirectX to me anyway :)

##### Share on other sites
Well with the new Macs being based on BSD means that Mac programming is basically Unix/Linux programming. And programming on thoes platforms are far more coherent, organized and straight forward that Windows. There are a very wide variety of free libraries with very flexible liscences.

Warning Rrant: And MS has problems with following standards. For example the standard library on Linux has always been ANSI compliant. Microsoft just released an ANSI compliant standard library with the newest visual studio. Hell with Visual Studio 6 their C++ compiler didn't even conform to the C++ standard properly.

Quote:
 So, inorder for the program to work for diff platforms (win, mac, linix), i need to compile the program on each OS?

Yes you will need to compile for each platform. Though availability of libraries on each system will mean you'll have to use #ifdef _WIN32 to choose between libraries for the appropriate platform.

You can make any program cross compile as long as you have access to the same or similar library on each system. You'll have to get used to using the "wrapper" design pattern where you write a class that wraps around the functionality of each library, abstracting which library is used.

Quote:
 Also, im pretty sure im going to be learning OpenGL pretty soon (maybe in a month), and if i program on a mac, all i need to do make it work for windows, is save to a memory stick, upload on my desktop, and compile the code on winXP, and not have to change 500 lines of coding?

Well sorta ... you'll have to do what I mentioned above unless you go on Windows and install something called Cygwin or Mingw. Thoes will provide you with Unix (remember MacOS is based on Unix) tools compiled for Windows. So you can use the same buld tools and libraries (if available) for both platforms.

Quote:
 The reason i ask, is that im pretty sure im going to probably get a macbook.

Apple laptops are pretty sweet. Thats all I have to say on that point.

##### Share on other sites
Quote:
 Original post by fpsgamerWell with the new Macs being based on BSD means that Mac programming is basically Unix/Linux programming. And programming on thoes platforms are far more coherent, organized and straight forward that Windows.For example the standard library on Linux has always been ANSI compliant. Microsoft just released an ANSI compliant standard library with the newest visual studio. Hell with Visual Studio 6 their C++ compiler didn't even conform to the C++ standard properly.

So programming on a mac will not give me errors with the code i have now?

Also, what do you mean that it is more coherent? (please give examples, i really want to know b4 i buy a mac)

##### Share on other sites
Quote:
 Original post by NUCLEAR RABBITSo, inorder for the program to work for diff platforms (win, mac, linix), i need to compile the program on each OS?

Or at least cross-compile it.

Quote:
 Also, im pretty sure im going to be learning OpenGL pretty soon (maybe in a month), and if i program on a mac, all i need to do make it work for windows, is save to a memory stick, upload on my desktop, and compile the code on winXP, and not have to change 500 lines of coding?

The OpenGL extension mechanisms are different on each platform, so you'll have to abstract that much at least. File paths will be different too.

Quote:
 The reason i ask, is that im pretty sure im going to probably get a macbook.

The integrated graphics on those isn't the best, maybe you need a pro :)

##### Share on other sites
Win32 is very direct and to the point generally.

VC6 is not a valid criticism because it was released back in 97, b4 the C++ standard was released.

VS2003 was the first attempt at a standards compliant C++ compiler, and VS2003 was the first good attempt. And VS2005 is one of the most standard compliant compilers on the market, rivals GCC and the code generation is much better.

Quote:
Original post by fpsgamer
Well with the new Macs being based on BSD means that Mac programming is basically Unix/Linux programming. And programming on thoes platforms are far more coherent, organized and straight forward that Windows. There are a very wide variety of free libraries with very flexible liscences.

Warning Rrant: And MS has problems with following standards. For example the standard library on Linux has always been ANSI compliant. Microsoft just released an ANSI compliant standard library with the newest visual studio. Hell with Visual Studio 6 their C++ compiler didn't even conform to the C++ standard properly.

Quote:
 So, inorder for the program to work for diff platforms (win, mac, linix), i need to compile the program on each OS?

Yes you will need to compile for each platform. Though availability of libraries on each system will mean you'll have to use #ifdef _WIN32 to choose between libraries for the appropriate platform.

You can make any program cross compile as long as you have access to the same or similar library on each system. You'll have to get used to using the "wrapper" design pattern where you write a class that wraps around the functionality of each library, abstracting which library is used.

Quote:
 Also, im pretty sure im going to be learning OpenGL pretty soon (maybe in a month), and if i program on a mac, all i need to do make it work for windows, is save to a memory stick, upload on my desktop, and compile the code on winXP, and not have to change 500 lines of coding?

Well sorta ... you'll have to do what I mentioned above unless you go on Windows and install something called Cygwin or Mingw. Thoes will provide you with Unix (remember MacOS is based on Unix) tools compiled for Windows. So you can use the same buld tools and libraries (if available) for both platforms.

Quote:
 The reason i ask, is that im pretty sure im going to probably get a macbook.

Apple laptops are pretty sweet. Thats all I have to say on that point.

##### Share on other sites
Basically if you want to get used to doing some system gui programming and how wrappers work then doing the wrapper yourself is a good project, if you want to start doing stuff with least bother then getting a window abstraction layer like SDL is the way to go. SDL mimicks win32 quite a bit in the way it does its calls, just dumbs it down a bit.

If you are learning to program 3d stuff, and want your stuff to work quickly on both platforms download a window layer like SDL or wxWindows etc.

##### Share on other sites
Quote:
 Original post by Anonymous PosterBasically if you want to get used to doing some system gui programming and how wrappers work then doing the wrapper yourself is a good project, if you want to start doing stuff with least bother then getting a window abstraction layer like SDL is the way to go. SDL mimicks win32 quite a bit in the way it does its calls, just dumbs it down a bit.If you are learning to program 3d stuff, and want your stuff to work quickly on both platforms download a window layer like SDL or wxWindows etc.

im not quite sure what youy mean about wrapper stuff. can someone please show me an example of code that would run on both mac and windows? or even show me an example of what i would have to change for things to work? simple examples such as like:

#include <string>#include <iostream>using namespace std;int main(){    string name;    cout << "Whats your name: ";    cin >> name;    cout << "Hello, " << name << "\n\n";    return 0;}

##### Share on other sites
That example will work. You create it under a C++ Command Line Utility in XCode.

The main thing with this is trying to create things which aren't part of the c++ standard. Such as, how would you create threads? Or how do you manage directories? Or how will you draw graphics or play music?

Just things that we take for granted now, but weren't exactly designed to be part of the language when it was created. At the time, you had different groups deciding their own way to do things, thus, no standardization.

A wrapper is basically something that takes these platform specific pieces of code, and adds another layer ontop of them.

Thus, a simple example.
Mac:

MyLibrary::DawGraphics()
{
MacGraphics.Draw();
}

Win:

MyLibrary::DrawGraphics()
{
WinGraphics.Draw();
}

Unix:

MyLibrary::DrawGraphics()
{
UnixGraphics.Draw();
}

MacGraphics.Draw isn't the same code as WinGraphics.Draw, and neither are the same code as UnixGraphics.Draw(). But I wrote this wrapper for all 3 systems. Thus, someone with a Mac, or Windows, or Unix, downloads MyLibrary. And when they want to draw graphics, they don't call those platform specific pieces of code, they call MyLibrary.Draw(). And because my wrapper is exists on multiple platforms, someone with a Mac can compile & run this same code the way a person on Windows or Unix can.

##### Share on other sites
I think what everyone means by wrapper is a class. Basically, you avoid doing this within your main program:
#ifdef __WIN32CreateWindowEx( params... );#endif#ifdef __APPLE__MacCreateWindow( params...); // or whatever the analogous function would be#endif#ifdef UNIXXCreateSimpleWindow( params... );#endif

If you accomodate for every platform right in line with the rest of you code, you make it at least three times as long, and at least three times as unreadable.

When you make a wrapper, you are hiding this under the hood. You create a class called, oh let's say, "PlatformManager". Then you create a member function called, let's say, "DoWindow()". Now here's what this function would look like:
[ReturnType] PlatformManager::DoWindow( params... ){  #ifdef __WIN32  CreateWindowEx( params... );  #endif  #ifdef __APPLE__  MacCreateWindow( params...); // or whatever the analogous function would be  #endif  #ifdef UNIX  XCreateSimpleWindow( params... );  #endif}

Now, in your main program, instead of calling the Windows or Mac or Unix API directly, you call your own function when you need to create a window:
#include "PlatformManager.h"...// Create a window regardless of what platform we are usingPlatformManager mgr;mgr.DoWindow( params... );

So, even though you are still accomodating for all the different platforms, you are now doing it under the hood, and your program is three times as short, and three times as clean. If you release your source code (as well as your platform manager), then your code could be compiled on Windows, and on Mac, and on Unix without having to change a single line of code.

Unfortunately, if you release your output executable file, you won't be able to run the same executable on three different machines. Remember, #ifdef is a preprocessor macro. If whatever you use it on is "defined", then the code between the #ifdef and the #endif is included and compiled; but if it is NOT defined, the compiler ignores it as if it was a comment. Essentially, 2/3 of the code I wrote above won't even be included in the output executable. So this approach does not make your executable file portable, it just makes your code portable.

Now, you can write your own PlatformManager, or you can use an existing one like wxWidgets. I would recommend you use an existing one, since they have been thoroughly tested, and in the case of wxWidgets, it has been more than a decade in production. And of course, if you run into a problem with wxWidgets, there is always a support forum. Unlike if you run into a problem with your own platform manager, then you would have to include it with every question you ask on the forum.

Finally (and my thread totally pwnz yours on this topic), if you want a portable executable, you can use a language such as Java, Python, Perl, and I think you can also use C#. I'm not sure if all .NET languages create portable executables - for example, I don't know about C++.NET

##### Share on other sites
Quote:
 Original post by v0dKAI think what everyone means by wrapper is a class. Basically, you avoid doing this within your main program:#ifdef __WIN32CreateWindowEx( params... );#endif#ifdef __APPLE__MacCreateWindow( params...); // or whatever the analogous function would be#endif#ifdef UNIXXCreateSimpleWindow( params... );#endifIf you accomodate for every platform right in line with the rest of you code, you make it at least three times as long, and at least three times as unreadable.When you make a wrapper, you are hiding this under the hood. You create a class called, oh let's say, "PlatformManager". Then you create a member function called, let's say, "DoWindow()". Now here's what this function would look like:[ReturnType] PlatformManager::DoWindow( params... ){ #ifdef __WIN32 CreateWindowEx( params... ); #endif #ifdef __APPLE__ MacCreateWindow( params...); // or whatever the analogous function would be #endif #ifdef UNIX XCreateSimpleWindow( params... ); #endif}Now, in your main program, instead of calling the Windows or Mac or Unix API directly, you call your own function when you need to create a window:#include "PlatformManager.h"...// Create a window regardless of what platform we are usingPlatformManager mgr;mgr.DoWindow( params... );So, even though you are still accomodating for all the different platforms, you are now doing it under the hood, and your program is three times as short, and three times as clean. If you release your source code (as well as your platform manager), then your code could be compiled on Windows, and on Mac, and on Unix without having to change a single line of code.Unfortunately, if you release your output executable file, you won't be able to run the same executable on three different machines. Remember, #ifdef is a preprocessor macro. If whatever you use it on is "defined", then the code between the #ifdef and the #endif is included and compiled; but if it is NOT defined, the compiler ignores it as if it was a comment. Essentially, 2/3 of the code I wrote above won't even be included in the output executable. So this approach does not make your executable file portable, it just makes your code portable.Now, you can write your own PlatformManager, or you can use an existing one like wxWidgets. I would recommend you use an existing one, since they have been thoroughly tested, and in the case of wxWidgets, it has been more than a decade in production. And of course, if you run into a problem with wxWidgets, there is always a support forum. Unlike if you run into a problem with your own platform manager, then you would have to include it with every question you ask on the forum.Finally (and my thread totally pwnz yours on this topic), if you want a portable executable, you can use a language such as Java, Python, Perl, and I think you can also use C#. I'm not sure if all .NET languages create portable executables - for example, I don't know about C++.NET

what if the programs are just console apps, no API's such as opengl or directX? Eventually i will move to openGL, but will basic console apps work on both mac and windows without making wrappers or platform specific coding?

##### Share on other sites
Quote:
 Original post by NUCLEAR RABBITwhat if the programs are just console apps, no API's such as opengl or directX? Eventually i will move to openGL, but will basic console apps work on both mac and windows without making wrappers or platform specific coding?

I don't think the .exe file would be portable. The same executable won't run on all systems. The code, however, would be portable. You can hand the source code to someone who uses Linux or Mac, and they will be able to compile it without changes.

By the way, can someone verify that anything created for the .NET framework is executable on all platforms? Or do you again have to compile it on the different platforms in order to run?

Anyhow, very soon, I will be able to give you some first-hand information. I'm preparing to install Ubuntu Linux on my old (trashy) computer. I'm downloading the operating system right now [smile]. But first, I have to do some MAJOR cleaning up on the old computer. It has very nearly exhausted its petty 5GB, but I'm too cheap to buy another hard drive.

Speaking of which (sorry to hijack thread with my own questions): the computer is currently a Windows 98. A lot of the programs in the Add/Remove Software list cannot be removed because they're missing an installation log file. Is it OK to simply right click and delete the directories where those programs are stored? Is it OK to just go through Program Files and delete folders willy-nilly? (After confirming, of course, that the software I'm deleting is truly not needed). Do programs generally trash up the computer in places other than Program Files? Anyone have any suggestions for cleaning out old computers?