Flags

An example of a function with flags as a parameter is declared as follows.
function SDL_Init( flags : uint32 ) : Integer;
Examples of flags taken from the documentation are SDL_INIT_TIMER, SDL_INIT_AUDIO, SDL_INIT_VIDEO, SDL_INIT_CDROM and SDL_INIT_JOYSTICK. The values for these flags are given in SDL.pas as the hex values 1, 10, 20, 100 and 200 respectively. The flags are stored as 32-bit unsigned integers. For each of these flags, the first 20 bits are zero. The remaining 12 bits are tabulated below.
SDL_INIT_TIMER 0000 0000 0001
SDL_INIT_AUDIO 0000 0001 0000
SDL_INIT_VIDEO 0000 0010 0000
SDL_INIT_CDROM 0001 0000 0000
SDL_INIT_JOYSTICK 0010 0000 0000

Note that in each flag there is a single 1-bit. In order to combine flags, we just perform a bitwise OR operation. For example, SDL_INIT_AUDIO OR SDL_INIT_VIDEO has the bit pattern 0000 0000 0000 0000 0000 0000 0011 0000.

In the source code SDL.c, each flag appears in expressions such as: flags & SDL_INIT_VIDEO (where & in c is the equivalent of the bitwise operator AND in Pascal). Confirm for yourself that this expression will evaluate to 0 (and be treated as False in C) if the video flag has not been included.

Note that the instruction SDL_Init(SDL_INIT_AUDIO OR SDL_INIT_VIDEO) will initialise the Audio and Video parts of SDL.

Programming - a skill for life!

How to use SDL parameters such as flags and PChar strings