Skip to content

Commit f8c058a

Browse files
Updates STYLESHEET: bool/Boolean treatment
1 parent 824fcb3 commit f8c058a

File tree

1 file changed

+7
-46
lines changed

1 file changed

+7
-46
lines changed

STYLESHEET.md

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ data types. For Delphi we have a temporary solution provided.
2121

2222
**Example:** Use `cuint32` (if `Uint32` is used in
2323
the original code) instead of `UInt32`, `Cardinal`, `LongWord` or `DWord`.
24-
Exception: Replace `*char` by `PAnsiChar`.
24+
Exception 1: Replace `*char` by `PAnsiChar`.
2525

26-
**Hint:** Use `TSDL_Bool` to translate `SDL_bool`. For macro functions use `Boolean`.
26+
4. In SDL3 the type `SDL_Bool` has been replaced by plain `bool`. C's bool is usually 1 byte in size
27+
and therefore fully memory comaptible with Free Pascal's and Delphi's Boolean.
28+
Hence we translate `bool` by `Boolean`.
2729

28-
4. If an identifier or a function declaration is gone, mark them as `deprecated`.
30+
5. If an identifier or a function declaration is gone, mark it as `deprecated`.
2931

30-
5. For convenience we encourage to add single and double pointers for any SDL type.
32+
6. For convenience we encourage to add single and double pointers for any SDL type.
3133

3234
## Defines
3335

@@ -319,45 +321,4 @@ return values depend on the context in which this macro is used. Here from the
319321
context is known that X, Y and Z stand for the major version, minor version and
320322
the patch level which are declared to be 8 bit unsigned integers. From the
321323
context it is also clear, that the macro returns true or false, hence the
322-
function should return a Boolean value. The context does not suggest to use,
323-
e. g., TSDL_Bool here, although in a different context this could be the better
324-
translation.
325-
326-
## When to use TSDL_Bool?
327-
328-
TSDL_Bool is memory compatible with C's bool (integer size, e. g. 2 or 4 bytes).
329-
Pascal's Boolean is different and typically 1 byte in size. ([FPC Ref.](https://www.freepascal.org/docs-html/current/ref/refsu4.html#x26-270003.1.1))
330-
331-
* return values and paramters of original SDL functions which are of SDL_Bool type, should be translated with TSDL_Bool
332-
* DO NOT use TSDL_Bool for macro functions which evaluate to a boolean value, use Pascal's Boolean instead (exception: the value is an argument for a SDL_Bool parameter)
333-
334-
_Example code_
335-
```pascal
336-
program SDLBoolTest;
337-
338-
uses SDL2, ctypes, SysUtils;
339-
340-
var
341-
a, b: Integer;
342-
343-
function BoolTest(a, b: Integer): TSDL_Bool;
344-
begin
345-
// works
346-
//Result := TSDL_Bool(a > b);
347-
348-
// works, too
349-
Result := (a > b);
350-
end;
351-
352-
begin
353-
writeln('Bool Test a > b');
354-
for a:= 0 to 3 do
355-
for b := 0 to 3 do
356-
begin
357-
write('a = ' + IntToStr(a) + '; b = ' + IntToStr(b) +'; Result = ');
358-
writeln(BoolTest(a, b));
359-
end;
360-
361-
readln;
362-
end.
363-
```
324+
function should return a Boolean value.

0 commit comments

Comments
 (0)