[fpc-pascal] os dependency with ifdef
Tomas Hajny
XHajT03 at mbox.vol.cz
Fri Mar 17 11:11:18 CET 2006
Marc Santhoff wrote:
Hi,
> I' like to know how I should write code for different system. SInce I'm
> no Linux user nor have any experience on MacOS I need to know how to
> wrap platform dependant code.
>
> Since I'm still fiddling with reading the serial port I have the idea
> that linux and even MacOS may be very similar to my main os FreeBSD.
>
> I do know Win32 is different, but how similar are the other os'ses?
>
> Is there any code in the FCL or the like I can study for getting my
> ifdefs right?
If you really want to create it prepared for current and future platforms,
don't do it via IFDEFs first of all. The procedural solution would be to
design a logical layer for functionality you need (get permissions for
accessing port, open port, set characteristics, read data, write data,
close port) in common interface part of a unit created as an include file,
possibly create (an)other include file(s) with shared parts of the
implementation too and create standalone units for the different platforms
you need to support.
Alternative solution (slightly more OOP-like and, somewhat easier to
implement and providing more flexibility) is to use create a "manager"
record for your particular functionality - see e.g. the heap management
and thread management routines, plus keyboard, mouse and video management
provided in units of the same name.
Tomas
More information about the fpc-pascal
mailing list