Skip to content

Commit a998816

Browse files
Update test: Show use of C's variadic functions
1 parent 0e7f36b commit a998816

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

tests/testver.pas

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
{ Test is based on testver.c }
1010

11+
{$DEFINE C_VARIADIC_LOG} // !!! This define compiles Case 2. Comment out for Case 1 !!!
12+
1113
program testver;
1214

1315
uses
14-
SDL3, SysUtils;
16+
SDL3 {$IFNDEF C_VARIADIC_LOG}, SysUtils{$ENDIF};
1517

1618
var
1719
version: Integer;
@@ -22,13 +24,39 @@
2224
else
2325
SDL_Log('Compiled with SDL older than 3.0');
2426

27+
{ Case 1: Do NOT use C's variadic function:
28+
29+
Uses SDL_Log(fmt: PAnsiChar) with only the string parameter.
30+
There is not variadic part in the SDL function itself.
31+
32+
The variadic part is provided by Pascal's Format() function
33+
from SysUtils. }
34+
{$IFNDEF C_VARIADIC_LOG}
35+
SDL_Log('Case 1: SDL_Log without variadic part.');
2536
SDL_Log(PChar(Format('Compiled version: %d.%d.%d (%s)',[
2637
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION,
2738
SDL_REVISION])));
2839
version := SDL_GetVersion();
2940
SDL_Log(PChar(Format('Runtime version: %d.%d.%d (%s)',
3041
[SDL_VERSIONNUM_MAJOR(version), SDL_VERSIONNUM_MINOR(version), SDL_VERSIONNUM_MICRO(version),
3142
SDL_GetRevision()])));
43+
{$ENDIF}
44+
45+
{ Case 2: Use C's variadic function:
46+
47+
Uses SDL_Log(fmt: PAnsiChar; Args: array of const). The variadic part
48+
is provided directly by C's function. SysUtils is not needed. }
49+
{$IFDEF C_VARIADIC_LOG}
50+
SDL_Log('Case 2: SDL_Log with variadic part.');
51+
SDL_Log('Compiled version: %d.%d.%d (%s)', [
52+
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION,
53+
SDL_REVISION]);
54+
version := SDL_GetVersion();
55+
SDL_Log('Runtime version: %d.%d.%d (%s)',
56+
[SDL_VERSIONNUM_MAJOR(version), SDL_VERSIONNUM_MINOR(version), SDL_VERSIONNUM_MICRO(version),
57+
SDL_GetRevision()]);
58+
{$ENDIF}
59+
3260
SDL_Quit();
3361
end.
3462

0 commit comments

Comments
 (0)