 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
isaac Guest
|
Posted: Tue Jan 27, 2004 10:55 am Post subject: cross-platform development: Windows -> Solaris |
|
|
We are building a code base that must run on Solaris. We are thinking
of developing on Windows Visual C++ ( but turning off Microsoft
extensions ) for the nice IDE and running our big projects on Solaris,
rather than developing on
Solaris exclusively. The two versions do not need to share input /
output files, btw.
What general categories of C++ code will be system dependent between
Windows and Solaris? What is a good process for sectioning off
system-dependent code? Let's assume only ANSI Standard C++ is used,
as well as basic STL. I have down:
- networking
- multithreading
- size of certain data types
I'm new to porting code, so any resources / books to read would be
very valuable.
Thanks,
Isaac
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Attila Feher Guest
|
Posted: Tue Jan 27, 2004 6:47 pm Post subject: Re: cross-platform development: Windows -> Solaris |
|
|
isaac wrote:
| Quote: | We are building a code base that must run on Solaris. We are thinking
of developing on Windows Visual C++ ( but turning off Microsoft
extensions ) for the nice IDE and running our big projects on Solaris,
[SNIP] |
Did you actually try to switch it off? With 6.0 I have tried and even a
standard Hello World program did not compile.
--
Attila aka WW
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Jeff Schwab Guest
|
Posted: Wed Jan 28, 2004 9:38 am Post subject: Re: cross-platform development: Windows -> Solaris |
|
|
isaac wrote:
| Quote: | We are building a code base that must run on Solaris. We are thinking
of developing on Windows Visual C++ ( but turning off Microsoft
extensions ) for the nice IDE and running our big projects on Solaris,
rather than developing on
Solaris exclusively. The two versions do not need to share input /
output files, btw.
What general categories of C++ code will be system dependent between
Windows and Solaris? What is a good process for sectioning off
system-dependent code? Let's assume only ANSI Standard C++ is used,
as well as basic STL. I have down:
- networking
- multithreading
- size of certain data types
I'm new to porting code, so any resources / books to read would be
very valuable.
|
Is there a reason to develop on Windows? If it's the expense of the
boxes, you could just run Solaris x86. Even Linux or FreeBSD would be
much more Solaris-like than Windows. If you need Windows for some
unrelated purpose, could you use dual-boot machines?
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Thomas Richter Guest
|
Posted: Wed Jan 28, 2004 9:59 am Post subject: Re: cross-platform development: Windows -> Solaris |
|
|
Hi,
| Quote: | What general categories of C++ code will be system dependent between
Windows and Solaris? What is a good process for sectioning off
system-dependent code? Let's assume only ANSI Standard C++ is used,
as well as basic STL. I have down:
- networking
- multithreading
- size of certain data types
I'm new to porting code, so any resources / books to read would be
very valuable.
|
Depends pretty much on what you're going to develop. A couple of
additional standard issues include:
- endianness. Don't assume any bit-order.
- whether char is signed or unsigned. Specify if it makes a difference.
- avoid win typical includes (i.e. windows.h)
- win does not provide some of the unixoid functions, e.g.
those under unistd.h (windows: a subclass is available in io.h)
- ensure that, if you're opening files, you specify whether this
happens in text or in binary mode. This makes no difference for
solaris. (E.g. "rb" vs. "r" in fopen).
- add a general warning about floating points. Results might
differ due to different rounding modes (the usual problem).
- The VS compiler handles variable declarations as in
for(int i = 0;...)
differently.
- Feel prepared to run into troubles with templates if you're using
the VS 6.0 compiler. The 7.1 should be fine, though.
- VS 6.0 might not handle "operator new" in a standard-conformant way,
i.e. does not throw on "out of memory". Tests for null-ness are
required. Again, 7.1 is fine.
So long,
Thomas
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Jeff Greif Guest
|
Posted: Wed Jan 28, 2004 10:16 am Post subject: Re: cross-platform development: Windows -> Solaris |
|
|
"isaac" <isaacjunk (AT) hotmail (DOT) com> wrote
| Quote: | We are building a code base that must run on Solaris. We are thinking
of developing on Windows Visual C++ ( but turning off Microsoft
extensions ) for the nice IDE and running our big projects on Solaris,
rather than developing on
Solaris exclusively. The two versions do not need to share input /
output files, btw.
What general categories of C++ code will be system dependent between
Windows and Solaris? What is a good process for sectioning off
system-dependent code? Let's assume only ANSI Standard C++ is used,
as well as basic STL. I have down:
- networking
- multithreading
- size of certain data types
|
Yes to all of these. Depending upon what you're doing, there may also be
issues of byte order (where does the least significant byte of a 16-bit
integer go).
You can for the most part hide these system dependencies by using a library
that abstracts them away (presenting the same interface on all platforms
supported). One such is ACE (Adaptive Communications Environment). See
http://www.cs.wustl.edu/~schmidt/ACE.html.
Jeff
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Eugene Alterman Guest
|
Posted: Wed Jan 28, 2004 1:34 pm Post subject: Re: cross-platform development: Windows -> Solaris |
|
|
"Attila Feher" <attila.feher (AT) lmf (DOT) ericsson.se> wrote
| Quote: | isaac wrote:
We are building a code base that must run on Solaris. We are thinking
of developing on Windows Visual C++ ( but turning off Microsoft
extensions ) for the nice IDE and running our big projects on Solaris,
[SNIP]
Did you actually try to switch it off? With 6.0 I have tried and even a
standard Hello World program did not compile.
|
This is definitely not true!
Just try the "Hello world" project that is conveniently provided by the MS
Visual Studio 6.0 project creation wizard.
In fact it is <windows.h> header that fails to compile with C++ extensions
turned off which makes it an issue of WIN32 specific code.
With proper design only those files in portability layer implementation will
use platform specific API and need to include <windows.h>.
The layers above may be compiled with the extensions turned off.
If I recall correctly, this approach is used in IBM's International
Components for Unicode.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Eugene Alterman Guest
|
Posted: Wed Jan 28, 2004 1:37 pm Post subject: Re: cross-platform development: Windows -> Solaris |
|
|
"isaac" <isaacjunk (AT) hotmail (DOT) com> wrote
| Quote: | We are building a code base that must run on Solaris. We are thinking
of developing on Windows Visual C++ ( but turning off Microsoft
extensions ) for the nice IDE and running our big projects on Solaris,
rather than developing on
Solaris exclusively. The two versions do not need to share input /
output files, btw.
What general categories of C++ code will be system dependent between
Windows and Solaris?
|
Any code that directly accesses native operating system services or uses
platform specific libraries.
| Quote: | What is a good process for sectioning off
system-dependent code?
|
Placing all the platform dependent code into a relatively thin portability
(platform adaptation) layer. This layer should be implemented separately for
each platform.
| Quote: | Let's assume only ANSI Standard C++ is used,
as well as basic STL. I have down:
- networking
- multithreading
- size of certain data types
|
Unfortunately both networking and multithreading are not covered by the
standard C++, so you will need additional resources to be able to use them
portably.
I recommend you to consider the Adaptive Communication Environment framework
(ACE) ( http://www.cs.wustl.edu/~schmidt/ACE.html)
I don't see any issues with different sizes of data types if you use
portable code.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Sergei Emantayev Guest
|
Posted: Wed Jan 28, 2004 1:47 pm Post subject: Re: cross-platform development: Windows -> Solaris |
|
|
[email]isaacjunk (AT) hotmail (DOT) com[/email] (isaac) wrote in message news:<8c3264f8.0401261452.28576232 (AT) posting (DOT) google.com>...
| Quote: |
What general categories of C++ code will be system dependent between
Windows and Solaris? What is a good process for sectioning off
system-dependent code? Let's assume only ANSI Standard C++ is used,
as well as basic STL. I have down:
- networking
- multithreading
- size of certain data types
|
WIN32 platform has a slightly different sockets implementation (called
WinSock) and totally different thread library.
I would suggest you to use a cross-platform library such as ACE to
avoid writing system specific code.
| Quote: |
I'm new to porting code, so any resources / books to read would be
very valuable.
|
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
kanze@gabi-soft.fr Guest
|
Posted: Wed Jan 28, 2004 8:15 pm Post subject: Re: cross-platform development: Windows -> Solaris |
|
|
[email]isaacjunk (AT) hotmail (DOT) com[/email] (isaac) wrote in message
news:<8c3264f8.0401261452.28576232 (AT) posting (DOT) google.com>...
| Quote: | We are building a code base that must run on Solaris. We are thinking
of developing on Windows Visual C++ ( but turning off Microsoft
extensions ) for the nice IDE and running our big projects on Solaris,
rather than developing on Solaris exclusively. The two versions do
not need to share input / output files, btw.
|
Curious. For large projects (involving teams of people, instead of just
one or two people), I find the Solaris environment significantly better.
| Quote: | What general categories of C++ code will be system dependent between
Windows and Solaris?
|
Just about everything that isn't defined in the standard. The most
obvious differences involve the GUI API, Sockets, threading and
processes, interprocess communication, anything other than the most
trival IO (directory walking, for example, file access rights,
synchronization...), signal handling, error reporting...
| Quote: | What is a good process for sectioning off system-dependent code?
|
First, take advantage of third party libraries. I've heard good things
about wxWindows, for example, for the GUI. Corba is excellent for
interprocess communication. Boost has a threading library and a class
for file system functions, etc. Much of what you need may be already
available.
Then, use the compilation firewall idiom. Put the actual implementation
of the class in different directories, according to the system.
Something along the lines of:
Socket.hh:
class Socket
{
class Impl ;
public:
// portable interface...
private:
Impl* myImpl ;
} ;
Socket.cc:
#include "Socket.hh"
#include "Socket.mcc"
Windows/Socket.mcc:
Windows implementation...
Solaris/Socket.mcc:
Solaris implementation...
When compiling, add a -ISolaris or a /IWindows, according to the
platform.
| Quote: | Let's assume only ANSI Standard C++ is used, as well as basic STL. I
have down:
- networking
- multithreading
- size of certain data types
|
If you compile in 32 bit mode under Solaris, the size of most data types
will be the same. So will the representation, modulo byte order. So
don't write code which depends on byte order. In close to 20 years of C
and C++, I think the only byte order dependant code I've written was to
extract the sign, exponent and mantissa from a double. And that was
only in an implementation of the C library (functions frexp, ldexp and
modf), not in application code.
Globally, this should not cause any problems, even if you compile in 64
bit mode under Solaris. Provided you are using third party software (a
Corba implementation, for example) for marshalling/demarshalling.
For the rest, define what system services you need, try and find a third
party library which encapsulates them, and if you can't find one define an
abstraction for them, and implement as above.
Also be aware that to some degree, it will depend on what compiler
versions you have. VC++ 6.0 had very poor template support, for
example, and so some of the functionality of the STL wasn't available.
Sun CC also has some weaknesses, particularly in its library.
--
James Kanze GABI Software mailto:kanze (AT) gabi-soft (DOT) fr
Conseils en informatique orientée objet/ http://www.gabi-soft.fr
Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, +33 (0)1 30 23 45 16
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Anthony Williams Guest
|
Posted: Wed Jan 28, 2004 8:25 pm Post subject: Re: cross-platform development: Windows -> Solaris |
|
|
[email]isaacjunk (AT) hotmail (DOT) com[/email] (isaac) writes:
| Quote: | What general categories of C++ code will be system dependent between
Windows and Solaris? What is a good process for sectioning off
system-dependent code? Let's assume only ANSI Standard C++ is used,
as well as basic STL. I have down:
- networking
- multithreading
- size of certain data types
|
If you use a library like pthread-win32
([url]http://sources.redhat.com/pthreads-win32/)[/url], then you can write multi-threaded
code that works the same on Windows and Solaris.
Networking is similar, but different --- Windows Sockets is very similar to
BSD sockets, but there are key differences.
If you compile for 32-bit Solaris, the data types are identical in size, but
opposite in Endian (IIRC), but 64-bit Solaris is different (as you might
expect)
Anthony
--
Anthony Williams
Senior Software Engineer, Beran Instruments Ltd.
Remove NOSPAM when replying, for timely response.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Eugene Alterman Guest
|
Posted: Thu Jan 29, 2004 10:03 am Post subject: Re: cross-platform development: Windows -> Solaris |
|
|
"Thomas Richter" <thor (AT) cleopatra (DOT) math.tu-berlin.de> wrote
| Quote: | - The VS compiler handles variable declarations as in
for(int i = 0;...)
differently.
|
Not if compiled with 'Disable Language Extensions' compiler option.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Balog Pal Guest
|
Posted: Thu Jan 29, 2004 10:03 am Post subject: Re: cross-platform development: Windows -> Solaris |
|
|
"isaac" <isaacjunk (AT) hotmail (DOT) com> wrote
| Quote: | We are building a code base that must run on Solaris. We are thinking
of developing on Windows Visual C++ ( but turning off Microsoft
extensions ) for the nice IDE and running our big projects on Solaris,
rather than developing on
Solaris exclusively. The two versions do not need to share input /
output files, btw.
|
Shouldn't be a big problem. If you don't need GUI, just sit down and write
a few wrappers, then it's just plain programming. Or look out for existing
portable libs.
Some 5 years ago I wrote a program that compiled fine on NT and Solaris,
used threads, processed binary files (moving cross platforms), cryptography,
read smartcard attached to a serial port... I actually ported most of the
MFC (excluding afxwin) to see it it's possible. It is. If you need only a
few packages it's considerably less work.
| Quote: | What general categories of C++ code will be system dependent between
Windows and Solaris? What is a good process for sectioning off
system-dependent code? Let's assume only ANSI Standard C++ is used,
as well as basic STL. I have down:
- networking
- multithreading
- size of certain data types
|
net: sockets are slightly different, but you find a solid rundown on
differences in the MSDN. MT: I remember problems to implement
WaitForMultipleObjects at the time. (but it's not impossible, also it can be
avoided.) IIRC I had to use a mix of the pthread and solaris threading api
for the implementation. Also I couldn't create an effective interlocked
inc/dec for SPARC V8. The latter is no problem on V9, guess you'll not
need to support old hardware.
types were mostly the same except for the 64 bit ones. (and endianness, thet
depends not on being solaris but the processor used...) But for portable
work it's benefical to typedef your set of 8, 16, 32, 64 bits
signed/unsigned types and use those instead of builtins. The actual type
then can be picked differently on different platforms.
| Quote: | I'm new to porting code, so any resources / books to read would be
very valuable.
|
You'll need a single guy with knowledge of both platforms. He will create
the alternative implementation of the common classes abstracting the
system-dealing functions.
I don't predict him having a hard time, but you need someone with the
knowledge. Having only newbies is IMHO dangerous. Also not economic.
Learn from that guy, make him explan what he does and why. Books will
help you after you grasped the picture.
Paul
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Dylan Nicholson Guest
|
Posted: Thu Jan 29, 2004 3:05 pm Post subject: Re: cross-platform development: Windows -> Solaris |
|
|
[email]kanze (AT) gabi-soft (DOT) fr[/email] wrote in message news:<d6652001.0401280314.336e386e (AT) posting (DOT) google.com>...
| Quote: |
Then, use the compilation firewall idiom. Put the actual implementation
of the class in different directories, according to the system.
Something along the lines of:
Socket.hh:
class Socket
{
class Impl ;
public:
// portable interface...
private:
Impl* myImpl ;
} ;
Socket.cc:
#include "Socket.hh"
#include "Socket.mcc"
Windows/Socket.mcc:
Windows implementation...
Solaris/Socket.mcc:
Solaris implementation...
|
Curious, what's the 'm' supposed to stand for?
I've used a similar idiom, but simpler, where the header files are
always the same but the source files are (potentially) different,
which works fine most of the time but is a pain when for instance,
half of the code for the socket implementation is the same on 2 or 3
platforms, but different on one other. Still, I agree it's a lot
better than #define's everywhere (the only #define I use is for
instantiating wide-character versions of templates, as the syntax is
the same for all platforms, but some simply don't work).
Dylan
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Attila Feher Guest
|
Posted: Fri Jan 30, 2004 9:39 am Post subject: Re: cross-platform development: Windows -> Solaris |
|
|
Eugene Alterman wrote:
| Quote: | "Attila Feher" <attila.feher (AT) lmf (DOT) ericsson.se> wrote in message
news:bv5kqb$or3$1 (AT) newstree (DOT) wise.edt.ericsson.se...
isaac wrote:
We are building a code base that must run on Solaris. We are
thinking > > of developing on Windows Visual C++ ( but turning off
Microsoft > > extensions ) for the nice IDE and running our big
projects on Solaris, > [SNIP]
Did you actually try to switch it off? With 6.0 I have tried and
even a > standard Hello World program did not compile.
This is definitely not true!
|
It definitely is.
| Quote: | Just try the "Hello world" project that is conveniently provided by
the MS Visual Studio 6.0 project creation wizard.
|
Be careful of "conveniently provided" things...
The C++ Hello World does *not* compile in 6.0 with MS extensions off. This
is a well known fact. Try to compile anything using the standard C++
library and all MS extensions turned off.
As for the facts: the C++ (we are in a C++ newsgroup) hello world program
compiled with the extensions off, using VC++ 6.0 quits after 102 error
messages.
The C-style Hello World compiles, but that won't help you when you need to
work in C++.
--
Attila aka WW
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
kanze@gabi-soft.fr Guest
|
Posted: Sat Jan 31, 2004 1:11 am Post subject: Re: cross-platform development: Windows -> Solaris |
|
|
[email]dpnich (AT) optushome (DOT) com.au[/email] (Dylan Nicholson) wrote in message
news:<735eea53.0401282211.23a00cc1 (AT) posting (DOT) google.com>...
| Quote: | kanze (AT) gabi-soft (DOT) fr wrote in message
news:<d6652001.0401280314.336e386e (AT) posting (DOT) google.com>...
Then, use the compilation firewall idiom. Put the actual
implementation of the class in different directories, according to
the system. Something along the lines of:
Socket.hh:
class Socket
{
class Impl ;
public:
// portable interface...
private:
Impl* myImpl ;
} ;
Socket.cc:
#include "Socket.hh"
#include "Socket.mcc"
Windows/Socket.mcc:
Windows implementation...
Solaris/Socket.mcc:
Solaris implementation...
Curious, what's the 'm' supposed to stand for?
|
Machine.
| Quote: | I've used a similar idiom, but simpler, where the header files are
always the same but the source files are (potentially) different,
which works fine most of the time but is a pain when for instance,
half of the code for the socket implementation is the same on 2 or 3
platforms, but different on one other.
|
Well, that particular case works well with my system. I put the common
code in the .cc, and the dependant code in the .mcc. I'll also use a
..mhh (a dependant header) when necessary -- in a case like the above, my
..cc might look something like:
#include "Socket.hh"
#include "Socket.mhh"
struct Socket::Impl
{
// common data...
SystemDependantSocketData
myData ;
} ;
#include "Socket.mcc"
void
Socket::someFunction()
{
// Do some independant stuff...
myData.someFunction() ; // Dependant stuff...
// More independant stuff...
}
But generally, in such cases, I'd rather factor all of the dependant
stuff out into a separate class.
When there is a distinct probability that the dependant stuff will be
small and simple (e.g. a single int), and performance might be an issue,
I will also include the .mhh directly in the .hh, and forego the
compilation firewall.
But to be honest, the real reason I initially decided on a .cc which
included the .mcc (rather than just put all of the .cc in the dependant
directory) was that it happened to fit in better with the makefile
structure I was using at the time if all of the .cc were in the same
directory. I've since had to add enough extra features to my makefiles
that putting the .cc directly in the dependant directory would not cause
any problems now, but since what I have works (at least for me), I've
not attempted to fix it.
| Quote: | Still, I agree it's a lot better than #define's everywhere (the only
#define I use is for instantiating wide-character versions of
templates, as the syntax is the same for all platforms, but some
simply don't work).
|
The #define's aren't the problem, as long as the number is limited, and
they obey a strict naming convention. The problem I try to avoid is
#ifdef.
--
James Kanze GABI Software mailto:kanze (AT) gabi-soft (DOT) fr
Conseils en informatique orientée objet/ http://www.gabi-soft.fr
Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, +33 (0)1 30 23 45 16
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|