newbie windows developers

Member
Posts: 64
Joined: 2008.10
Post: #1
Hi,
I'm trying to port some c++ windows code to xcode and have hit a lot of gotchas. I was thinking of starting a thread for tips for windows developers that just have started with xcode. Do people here think that is useful?
Quote this message in a reply
Moderator
Posts: 335
Joined: 2002.04
Post: #2
There's a porting games to Mac section in the forum a couple of items below the iPhone dev one which has a lot of helpful data for Mac devs porting code from Windows/Linux to OS X.

It would probably be good to start the thread there as basic XCode for windows devs is practical for devs targeting the Mac with OS X as well as the iPhone and most of the basic XCode stuff isn't particularly iPhone specific.
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #3
captainfreedom Wrote:Hi,
I'm trying to port some c++ windows code to xcode and have hit a lot of gotchas. I was thinking of starting a thread for tips for windows developers that just have started with xcode. Do people here think that is useful?

I learned to program in the Windows environment and here's the best tip I can give you:

Never never never never NEVER NEVER NNEEVVEERR #include <windows.h>

edit: #include <nolongerportableccode.h>

edit: Avoid DirectX like the plague

edit: In fact, don't use Windows. Rasp
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #4
bmantzey Wrote:I learned to program in the Windows environment and here's the best tip I can give you:

Never never never never NEVER NEVER NNEEVVEERR #include <windows.h>

edit: #include <nolongerportableccode.h>

edit: Avoid DirectX like the plague

edit: In fact, don't use Windows. Rasp

I can't tell if this is a joke post or not, but if it isn't, could you include some rationale with each tip? Nothing in your post explains the reasons for doing any of the above.
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #5
LOL, sorry. I was in a silly mood when I posted that.

There is seriousness in it though.

C/C++ are portable languages. If you stick to the standards, you should be able to copy/paste your code and compile it on any platform.

When you #include <windows.h>, you're introducing platform specific code that will only compile in Windows.

DirectX is only useable in Windows. MS makes it easy for the average lament who doesn't care that there are other platforms besides Windows. The downside of this ease is, if you use DirectX, you will have to port it to OpenGL for it to run on any other platform, including OS X.

So, to sum it up: If you have DirectX code, it will need to be completely ported to OpenGL. If you are using anything in <windows.h>, you'll have to find Mac alternatives to those specifics.

Some examples are GetAsyncKeystate, WORD, DWORD, etc. GetTickCount, ummm....there are a lot of commonly used <windows.h> functions. windows.h also includes some of the standard headers, so anything that's giving you a compile error, find out what library it's coming from. It may be that through windows.h, that library was included, so just #include that specific library to retain that particular code.

Porting can be a pain in the butt, just start with whatever came out of windows.h. I'm not all that experienced with porting but what I do know is, windows.h == bad if you're looking for portable code.
Quote this message in a reply
Member
Posts: 67
Joined: 2006.07
Post: #6
bmantzey Wrote:C/C++ are portable languages. If you stick to the standards, you should be able to copy/paste your code and compile it on any platform.

I wouldn't necessarily say that. In theory, yes, C/C++ is unified across all platforms in terms of semantics, but practically speaking, you can really only copy/paste code and expect it to work on multiple platforms if it's relatively trivial. Things like differences in the implementation of compilers across different platforms, byte order issues (albeit kind of irrelevant nowadays), the nature of the platform itself, etc, would probably prevent you from being able to write C/C++ code that can run on anything without any modification, no matter how strictly you stick to the standards.

I'd prefer to say that you should be able to reuse standard C/C++ code across multiple platforms with minimal changes necessary.

bmantzey Wrote:DirectX is only useable in Windows. MS makes it easy for the average lament who doesn't care that there are other platforms besides Windows. The downside of this ease is, if you use DirectX, you will have to port it to OpenGL for it to run on any other platform, including OS X.

DirectX isn't just a graphics API. It's a little bit like what Apple's Game Sprockets were back in the old days -- basically a collection of multimedia and hardware-interfacing APIs specifically tailored for game developers. And while DirectX's graphics APIs, DirectDraw and Direct3D, are pretty widely used in the Windows world, OpenGL is also very common on the Windows platform as well. I don't have enough experience with Windows to say which is more widely used, but I'm almost certain that the majority of Windows games use either one or the other.

Still, if a Windows game fully utilized DirectX, then porting it would involve porting not just graphics code, but also input, sound, and networking code as well.

bmantzey Wrote:Porting can be a pain in the butt, just start with whatever came out of windows.h. I'm not all that experienced with porting but what I do know is, windows.h == bad if you're looking for portable code.

I'm not really experienced in porting either, but I'd guess that while, for the most part, porting largely involves translating platform-specific API calls, there would be some cases, like going from Win32 to Cocoa for example, where you'd have to basically rewrite the structure of the program in order to effectively port the application. Plus, there's always the fact that UI standards differ from platform to platform, which have to be taken into account as well.

Of course, if you're really going for portable, you could always just rewrite your code to utilize SDL, which automatically gives you OS X, Windows, and Linux. But even then, I wouldn't say you'd completely eliminate the porting process -- you'd just make it drastically easier.

EDIT: I didn't realize this was in the iPhone development forum. If you're talking about iPhone development instead, then SDL's pretty much out -- you'd have to go with learning the iPhone SDK itself, along with Cocoa and Objective-C. But you can still use OpenGL, albeit a stripped-down version called OpenGL ES.

Since when was "Fred" a placeholder variable?
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2009.01
Post: #7
top two tips...

intellisense = "esc" key
look up code in documentation = "control" left double-click
Quote this message in a reply
Post Reply