C++ Program coding for different platform.


I have been asked to develop a s/w in C++
which will use Dial up to modem,
sending data, receiving data and showing response.
It will be running as a deamon program
on Linux and NT/Win2000.

I have similar program developed on linux and i know how to do the coding part.

What is the best way to approach coding so that I do not
have to write seperate source code for linux and windows.

It will be command line based program.

Please suggest me how is coding for different platform handled so that same souce code with proper OS related handling instruction is achieved. I am not willing to use DJGPP (http://www.delorie.com/djgpp/). Please suggest any other ideas you have.


Who is Participating?
There is a product called Cygwin (http://sources.redhat.com/cygwin/) that provides a port of the UNIX API to Windoze. You could try that, it works quite well. There are other more costly packages out there as well. Personally (having been involved in a large port of a Unix app to NT) I'd opt for going native (unless you have a large pre-existing code base). You will end up with duplicate code but if you carefully define your object model and interfaces you can push all the O/S specific stuff right out into the periphery which makes it much easier to handle.

Your duplicate code will probably be in the handling of the device itself. If you're careful file handling and general stuff can be written in a way that works on both NT and Unix without loads of alternate source paths everywhere. You'll need to pay attention to code syntax since VC++ and other compilers often don't see eye to eye. There is some content on the Netscape web-site that is a guide to writing platform independant code - you might want to look at that.

You might want to take a look at how Apache and other open source projects handle the Unix/NT front. On the daemon front, in NT/Win2000 that's a service which requires a bunch of infrastructure. However, there are free packages around that effectively proxy the service code for you, you just write an executable in the same way you would for [x]inetd and the proxy exec's your code for you. You'll find references to these packages in most good VB and Java forums (since neither are ideal environments for handling the NT service API).
shindaAuthor Commented:
Thanks for the insight.

Till date i have only used GCC on linux. And we do not use any windows based productus or compilers.
Long back I used cygwin just to see how it handles my unix code on windows NT. Everything was working fine in terms of file handling but it was taking too much of CPU time whenever my program used to go in loop waiting for a file in a specific directory. I will check at Netscape sie for the guide.

Andrew: Have you used CYGWIN in your cross compilations on Windows 2000 ? Does it work well ?

Thanks a lot for your valueable suggestions.

Cygwin has come a long way now. I've used it on small green-field developments (to good effect) but I must admin I tend to go "native" unless I have a strong reason otherwise.
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "andrewschneider" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/commspt

Per recommendation, force-accepted by
Community Support Moderator
Experts Exchange
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.