[fpc-devel] Issue with Critical sections
Sergei Gorelkin
sergei_gorelkin at mail.ru
Wed Apr 4 17:29:21 CEST 2007
Wednesday, April 04, 2007, 5:13:43 PM, Vinzent wrote:
VH> On Wednesday 04 April 2007 12:59, Sergei Gorelkin wrote:
>> But EnterCriticalSection/LeaveCriticalSection also exist in Windows
>> API. And they are implemented in System unit without changing names.
>> Therefore, to make my code cross-platform, I have only to remove
>> Windows from uses clause - then cross-platform versions from System
>> unit will be used. This is fine.
VH> No. If you want to be cross-platform just do not use the "Windows" unit
VH> at all. Rather only use the functionality provided by the system unit,
VH> regardless of the compilation target.
VH> The "Windows" unit should generally only included if you write platform
VH> specific code and such code should be separated in its own include file
VH> or even unit anyway.
That is exactly what I'm speaking about. Removing 'Windows' from
uses clause is essentially stopping using it :) And if the code
continues to compile and work after that, it is just fine.
The code I was compiling was already cross-platform (Delphi/Kylix),
and 'uses Windows' was wrapped by {$IFDEF MSWINDOWS}. In Kylix,
InitializeCriticalSection and DeleteCriticalSection are implemented in
SysUtils unit, so any code using these functions continue to work
under Linux. It was surprise for me that this code could not compile
with FPC.
--
Best regards,
Sergei
More information about the fpc-devel
mailing list