Skip to content

TSDL_Bool not cbool #110

Description

@sechshelme

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

Activity

  1. Free-Pascal-meets-SDL-Website commented on Jan 23, 2023

    @Free-Pascal-meets-SDL-Website
    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

  2. sechshelme commented on Jan 23, 2023

    @sechshelme
    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);
  3. Free-Pascal-meets-SDL-Website commented on Jan 27, 2023

    @Free-Pascal-meets-SDL-Website
    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionDiscuss an idea/feature/PR/issue...

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions