[hashcash] Re: hashcash BSD vs GNU getopt bug (Re: documentation bug?)
- From: Jonathan Morton <chromi@xxxxxxxxxxxxxxxxxxxxx>
- To: hashcash@xxxxxxxxxxxxx
- Date: Sat, 28 Aug 2004 20:43:03 +0100
I often struggle with writing cross platform code. I wonder if anyone
has some good references or resources for this. I want to write
command
line code, or libraries suitable for linking with GUI front ends, which
will compile on Linux, BSD, Windows and Macs.
A big help in this direction would be to not even try to support MacOS
prior to X (aka "Classic"). OSX and Win32, as well as the more
traditional UNIXes, can all use a very similar programming model, with
a large enough subset to do most useful things easily. A few macros
and a bit of forethought will get you cross-platform and quite complete
threading, mutex and network support. The rest can largely be done
using the ANSI C library, which is always available.
MacOS Classic's programming model is hugely different, and requires
unsubtle hacks at the compiler end even to support the mandatory ANSI C
library. If you write a library that doesn't need to use the command
line, threading, I/O (including console) or networking at all, however,
it should work under Classic as long as you stick to strict ANSI. My
fastmint library adheres to this rule as much as possible - except for
the GNU assembly which is conditionalised - because it will potentially
need to run on all kinds of exotic systems, and particularly Classic.
An alternative is to write in Java, as relatively recent Classic
versions have good support for it - but it might give you COBOL
fingers. Another alternative might be Python, which can be combined
with the wxWindows graphic toolkit. If you must write in C or C++ and
need Classic support with a GUI, consider using SDL or a similar
cross-platform application framework. GLUT is often unfairly
overlooked for this purpose.
One useful piece of information would be symbols which are predefined
by the compiler (or preprocessor), for each architecture, that would
allow you to distinguish them reliably. I don't know a good source
for this. I have found that _WIN32 is good for identifying Windows
though.
Look for WIN32, __linux__, __unix__, __MACH__ to distinguish the
important platforms, and __GNUC__ to determine whether you're in GCC or
not. MacOS X is the one that defines __MACH__ - for some reason it
doesn't define __unix__. BSD and Linux should both define __unix__, as
should Solaris - on each of these, you can rely on POSIX support, which
is much broader than ANSI. If none of the above are present, you're
probably compiling for MacOS Classic (or Carbon, which is almost the
same), or possibly VMS, or some other exotic system where sticking as
close to ANSI as possible is advised.
To get GCC to tell you what it defines by default on a particular
machine, use the following:
$ echo "" | gcc -E -dD - | less
Here's an extract from the output on one of my Linux boxes:
#define __i386 1
#define __i386__ 1
#define i386 1
#define __tune_i586__ 1
#define __tune_pentium__ 1
#define __linux 1
#define __linux__ 1
#define linux 1
#define __unix 1
#define __unix__ 1
#define unix 1
#define __ELF__ 1
#define __gnu_linux__ 1
# 1 "<command line>"
#define __GNUC__ 3
#define __GNUC_MINOR__ 3
#define __GNUC_PATCHLEVEL__ 4
# 1 "<stdin>"
--------------------------------------------------------------
from: Jonathan "Chromatix" Morton
mail: chromi@xxxxxxxxxxxxxxxxxxxxx
website: http://www.chromatix.uklinux.net/
tagline: The key to knowledge is not to rely on people to teach you it.
- References:
- [hashcash] Re: hashcash BSD vs GNU getopt bug (Re: documentation bug?)
- From: "Hal Finney"
Other related posts:
- » [hashcash] hashcash BSD vs GNU getopt bug (Re: documentation bug?)
- » [hashcash] Re: hashcash BSD vs GNU getopt bug (Re: documentation bug?)
- » [hashcash] Re: hashcash BSD vs GNU getopt bug (Re: documentation bug?)
- » [hashcash] Re: hashcash BSD vs GNU getopt bug (Re: documentation bug?)
- » [hashcash] Re: hashcash BSD vs GNU getopt bug (Re: documentation bug?)
- » [hashcash] Re: hashcash BSD vs GNU getopt bug (Re: documentation bug?)
has some good references or resources for this. I want to write command
line code, or libraries suitable for linking with GUI front ends, which
will compile on Linux, BSD, Windows and Macs.
One useful piece of information would be symbols which are predefined by the compiler (or preprocessor), for each architecture, that would allow you to distinguish them reliably. I don't know a good source for this. I have found that _WIN32 is good for identifying Windows though.
- [hashcash] Re: hashcash BSD vs GNU getopt bug (Re: documentation bug?)
- From: "Hal Finney"