Am Mittwoch, dem 01. Nov 2006 schrieb Frank Heckenbach:
Only CInteger (and its unsigned variants), there's no CLongInt.
Okay, my fault.
Note that you have to change "LongInt" to "CInteger" and "PChar" to "CString" in SDL4fp.
BTW, GPC support both "PChar" and "CString" built-in. However, indeed I prefer to write "CString" when I mean a pointer to a "C string" (i.e., Chr(0)-terminated array of chars), instead of a pointer to a single character (which "PChar" is according to a common way of notation).
I knew that there is PChar in GPC, but I also prefer CString because of it's name.
One way to avoid the ifdefs might be a macro that expands to "external 'SDL'" in FPC, and just "external" in GPC (and perhaps taking care of the "cdecl" as well for FPC,
That's a very good idea. I've done it this way now:
{$IfDef __GPC__} {$L SDL} {$DEFINE libSDL external name} {$EndIf}
{$IfDef FPC} {$MACRO ON} {$DEFINE libSDL:=cdecl; external 'SDL' name} {$EndIf}
[...]
function SDL_Init(flags: Uint32): CInteger; libSDL 'SDL_Init';
to further save typing).
It's not for the typing, but the result is much more readable.
C is case sensitive, while Pascal is not. So in GPC all Pascal identifiers are converted to lowercase at an early stage, this includes the procedure names. So you have a problem when your C identifiers need uppercase letters. This can only be solved by using an attribute which mentions the name again with its capitalisation: "name 'Example'".
Even when they don't need any uppercase letters, it's recommended to always specify the linker name for external declarations.
I see that there are reasons for the compiler developers. But it is much more convenient for the programmer, if the name would simply be deduced from the Pascal name with its capitalisation, as it is in Free Pascal.
Well I still have a problem with CString parameters. FPC needs a type cast, while GPC doesn't accept a type cast here. I "solved" it again with "IfDef"s. Does anybody know a better solution?
Perhaps another macro (just a quick idea, as I actually don't like macros too much), that does a type-cast in FPC and nothing in GPC. (Perhaps it could even be a type equal to CString in FPC, though with another name, working as a type-cast by itself, and a nop-macro in GPC.)
Can you tell me more about "nop-macros" in GPC?
Another macro would even be dirtier than the ifdef. Fortunately there are just few (only one?) situation, where that's needed in the SDL - so that doesn't harm much in my program.