Solved

C++ Program  coding for different platform.

Posted on 2001-08-21
5
209 Views
Last Modified: 2012-06-27
Hi,

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.

Regards,
Shinda

0
Comment
Question by:shinda
5 Comments
 

Accepted Solution

by:
andrewschneider earned 100 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).
0
 

Author Comment

by:shinda
ID: 6415130
Hi,
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.
Regards,
Shinda

0
 

Expert Comment

by:andrewschneider
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.
0
 
LVL 11

Expert Comment

by:griessh
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

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 5

Expert Comment

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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now