Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSDL_Bool not cbool #110

Open
sechshelme opened this issue Jan 22, 2023 · 3 comments
Open

TSDL_Bool not cbool #110

sechshelme opened this issue Jan 22, 2023 · 3 comments
Labels
discussion Discuss an idea/feature/PR/issue...

Comments

@sechshelme
Copy link

sechshelme commented Jan 22, 2023

SetColorKey requires an integer as the second parameter.
(SDL_surface.h; line: 446)

extern DECLSPEC int SDLCALL SDL_SetColorKey(SDL_Surface * surface, int flag, Uint32 key);

And SDL_FALSE & SDL_TRUE are also declared as integers.
(SDL_stdinc.h; line: 184)

typedef enum
{
     SDL_FALSE = 0,
     SDL_TRUE = 1
} SDL_bool;

So, in my opinion, TSDL_Bool should also be declared as an integer.
I modified the following in "sdlstdinc.inc":

type
   TSDL_Bool = cint;
// TSDL_Bool = cbool;

Do you also think that this is more the case?

I am using Lazarus 2.2.4

@Free-Pascal-meets-SDL-Website
Copy link
Collaborator

Hi @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_Bool but rather with the flawed data type if the flag argument in SDL_SetColorKey. The flag should be of SDL_bool type instead of int type.

You should go with a cint type-cast instead of changing the TSDL_Bool data type. Use for example cint(SDL_TRUE) or Integer(SDL_TRUE) for the flag argument.

Best regards
Matthias

@sechshelme
Copy link
Author

And 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
Copy link
Collaborator

@sechshelme

I 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 type

Case 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_FALSE to 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 use SDL_TRUE in 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_TRUE and SDL_FALSE as this is their actual meaning. - In C there is no other way as to represent them as integers, but nobody would actually do something like SDL_FALSE + 3 * SDL_TRUE; you see what I mean.

Best regards
Matthias

@Free-Pascal-meets-SDL-Website Free-Pascal-meets-SDL-Website added the discussion Discuss an idea/feature/PR/issue... label Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Discuss an idea/feature/PR/issue...
Projects
None yet
Development

No branches or pull requests

2 participants