[fpc-devel] Win32 RTL: Strange definition of constants in defines.inc

Frank Kintrup frank.kintrup at gmx.de
Tue Jan 4 18:06:28 CET 2005


I've found that the definition of some constants like RT_RCDATA
or IDI_EXCLAMATION from the latest RC1 is a little bit strange.
These "constants" are defined as functions, which return a value
using the function MakeIntResource, which in turn does a type
casting from integer to LPTSTR. So all this only does returning
a fixed integer value as LPTSTR.

Why do this? Even if inline functions would remove most of the
overhead, it seems odd. The compiler perfectly understands a
type cast in a constant definition like

const TestConst = LPTSTR(5);

At least in Delphi mode this compiles fine. I didn't check the
other modes, though.

Another side effect of this function approach is that these
"constants" can never be used as values for default parameters.
The following function does not compile in FPC 1.9.6, but works
fine in Delphi:

function GetResource(
  lpszName : PChar;
  szType   : PChar = RT_RCDATA;
  hInst    : HINST = 0) : Pointer;



More information about the fpc-devel mailing list