Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-03

os dependency with ifdef

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Santhoff

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?

TIA,
Marc

Tomas Hajny
to Marc Santhoff

Marc Santhoff wrote:

Hi,

Show quoted text 11 lines
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

Marc Santhoff
to Tomas Hajny
Tomas Hajny wrote 25 lines
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.

This is what I'm beginning to do at the moment, after some information retrieval about how serial ports on Win32 work I've come to the conclusion that porting the unit rtl/unix/serial.pp would be the best thing for my special task.

I'm only bothered by the design of that stuff, no result codes (procedure not function) in some important areas. But I will not make changes breaking old code, I hope some exception throwing will do ...

Show quoted text 5 lines
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.

Yes, if I had to design it from the start I would think about making it a really universally usable and technically perfect solution. But for now my goal is to get some very simple communication running on windows (slow, no handshake).

Thanks,
Marc

Felipe Monteiro de Carvalho
to Marc Santhoff: I' like to know how I should write code for different system. SInce I'm no Linux user nor…

Hello,

Marc Santhoff wrote
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?

You can mostly assume that if it works for Linux, then it will work for FreeBSD and all other BSDs and even Solaris (and vice-versa).

This isn´t true for Mac OS X. Althought it is based on FreeBSD, it is very, very different from standard unix boxes.

Is there any code in the FCL or the like I can study for getting my ifdefs right?

I used ifdefs to write two cross-platform projects: TTrayIcon component and the Virtual Magnifying Glass. You can see their codes on the internet.

For the magnifier, look for the LoadBitmap procedure to see a example of how to use a ifdef to implement a function that is very different on both platforms

http://cvs.sourceforge.net/viewcvs.py/magnifier/magnifierv3/glass.pas?rev=1.14&view=auto

TTrayIcon code is here:

http://www.freepascal.org/cgi-bin/viewcvs.cgi/trunk/components/trayicon/?root=lazarus

thanks,

Felipe Monteiro de Carvalho
Marc Santhoff
to Felipe Monteiro de Carvalho

Am Freitag, den 17.03.2006, 15:26 -0300 schrieb Felipe Monteiro de Carvalho:

Show quoted text 13 lines
Hello, On 3/16/06, Marc Santhoff wrote: > 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? You can mostly assume that if it works for Linux, then it will work for FreeBSD and all other BSDs and even Solaris (and vice-versa). This isn´t true for Mac OS X. Althought it is based on FreeBSD, it is very, very different from standard unix boxes.

I see, this is very valuable information.

Show quoted text 6 lines
> Is there any code in the FCL or the like I can study for getting my > ifdefs right? I used ifdefs to write two cross-platform projects: TTrayIcon component and the Virtual Magnifying Glass. You can see their codes on the internet.

Since I'm dealing with non-visible, non-component code I'll try making portable units out of it.

Maybe I'm coming back on this when the basics are done and the code using these units is in shape for building a component.

Thank you very much,
Marc

Jonas Maebe
to Felipe Monteiro de Carvalho: You can mostly assume that if it works for Linux, then it will work for FreeBSD and all…
Felipe Monteiro de Carvalho wrote 5 lines
You can mostly assume that if it works for Linux, then it will work for FreeBSD and all other BSDs and even Solaris (and vice-versa). This isn´t true for Mac OS X. Althought it is based on FreeBSD, it is very, very different from standard unix boxes.

It shares at least 90% of the rtl with the other BSD's, so it isn't that different at the basic unix level. It's mainly different if you want to use OS X-specific functionality (like its gui environment instead of X11). Regarding serial port stuff: none of the Macs which can run the latest version of Mac OS X still has a serial port. There are USB-serial converters out there though, and their drivers (.e.g from Keyspan) create a regular serial port device in /dev which works identically to those under other unixes.

It's not because other interfaces are available, that there is no compatibility with the traditional unix way of working.

Jonas