C++ Program  coding for different platform.

Posted on 2001-08-21
Medium Priority
Last Modified: 2012-06-27

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.


Question by:shinda
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

andrewschneider earned 400 total points
ID: 6412702
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).

Author Comment

ID: 6415130
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.


Expert Comment

ID: 6416753
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.
LVL 11

Expert Comment

ID: 6861804
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


Expert Comment

ID: 6883890
Per recommendation, force-accepted by
Community Support Moderator
Experts Exchange

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question