Repository navigation
TSDL_Bool not cbool #110
Description
Activity
Free-Pascal-meets-SDL-Website commented
on Jan 23, 2023 CollaboratorMore actionsHi @sechshelme,
we had a longer discussion about handling of SDL_bool in this issue: #30
Since the boolean data type is not the same as the integer data type (although they can be implemented via integer types) they should be distinguished. In contrast to C this is strongly done in Pascal, hence the problem is not with
TSDL_Boolbut rather with the flawed data type if the flag argument inSDL_SetColorKey. The flag should be ofSDL_booltype instead ofinttype.You should go with a cint type-cast instead of changing the TSDL_Bool data type. Use for example
cint(SDL_TRUE)orInteger(SDL_TRUE)for the flag argument.Best regards
MatthiasAnd who would change it like that?
type TSDL_Bool = cbool; const SDL_FALSE = 0; SDL_TRUE = 1; // SDL_FALSE = TSDL_Bool(0); // SDL_TRUE = TSDL_Bool(1);
or
const SDL_FALSE = cint(0); SDL_TRUE = cint(1);
Free-Pascal-meets-SDL-Website commented
on Jan 27, 2023 CollaboratorMore actionsI see your point, but please consider these two functions which will just return the arguments bool value:
(1) function BoolArgument(ABool: TSDL_Bool); TSDL_Bool;
(2) function IntArgument(ABoolFlag: cint): TSDL_Bool;Case 1: SDL_TRUE/SDL_FALSE is declared as is in our headers:
BoolArgument(SDL_True); // returns True IntArgument(SDL_True); // compiling error: argument must be of integer typeCase 2: SDL_TRUE/SDL_FALSE is declared as you propose as integers:
BoolArgument(SDL_True); // compiling error: argument must be of bool type IntArgument(SDL_True); // returns True (if casted within the function body)As Pascal strongly distinguishes the bool type from the integer type there cannot be ONE declaration for
SDL_TRUE/SDL_FALSEto fit both cases. In contrast to this in C the bool type is a simple integer type which is interpreted as a bool type, hence you can useSDL_TRUEin both cases without compiler errors. In Pascal at some point there has to be a type-cast.We decided to go for a bool type representation by
SDL_TRUEandSDL_FALSEas this is their actual meaning. - In C there is no other way as to represent them as integers, but nobody would actually do something likeSDL_FALSE + 3 * SDL_TRUE; you see what I mean.Best regards
Matthias- addeddiscussionDiscuss an idea/feature/PR/issue...Discuss an idea/feature/PR/issue...
on Jan 27, 2023
SetColorKey requires an integer as the second parameter.
(SDL_surface.h; line: 446)
And SDL_FALSE & SDL_TRUE are also declared as integers.
(SDL_stdinc.h; line: 184)
So, in my opinion, TSDL_Bool should also be declared as an integer.
I modified the following in "sdlstdinc.inc":
Do you also think that this is more the case?
I am using Lazarus 2.2.4