Fixed bug 1882 - SDL_GetKeyboardState should return const.
authorSam Lantinga <slouken@libsdl.org>
Sun, 02 Jun 2013 01:09:12 -0700
changeset 725889d47188c9a4
parent 7257 5997d00782e8
child 7259 be3edef98d4b
Fixed bug 1882 - SDL_GetKeyboardState should return const.

Yuri K. Schlesner

The array returned by SDL_GetKeyboardState is also used internally by SDL to keep track of pressed/released keys and must not be modified, lest weird behaviour occurs. Because of this I believe it's return type should be changed to return a const pointer, which will provide a code indication of that fact.
include/SDL_keyboard.h
src/events/SDL_keyboard.c
     1.1 --- a/include/SDL_keyboard.h	Sun Jun 02 01:08:14 2013 -0700
     1.2 +++ b/include/SDL_keyboard.h	Sun Jun 02 01:09:12 2013 -0700
     1.3 @@ -66,13 +66,13 @@
     1.4   *
     1.5   *  \b Example:
     1.6   *  \code
     1.7 - *  Uint8 *state = SDL_GetKeyboardState(NULL);
     1.8 + *  const Uint8 *state = SDL_GetKeyboardState(NULL);
     1.9   *  if ( state[SDL_SCANCODE_RETURN] )   {
    1.10   *      printf("<RETURN> is pressed.\n");
    1.11   *  }
    1.12   *  \endcode
    1.13   */
    1.14 -extern DECLSPEC Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys);
    1.15 +extern DECLSPEC const Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys);
    1.16  
    1.17  /**
    1.18   *  \brief Get the current key modifier state for the keyboard.
     2.1 --- a/src/events/SDL_keyboard.c	Sun Jun 02 01:08:14 2013 -0700
     2.2 +++ b/src/events/SDL_keyboard.c	Sun Jun 02 01:09:12 2013 -0700
     2.3 @@ -829,7 +829,7 @@
     2.4  {
     2.5  }
     2.6  
     2.7 -Uint8 *
     2.8 +const Uint8 *
     2.9  SDL_GetKeyboardState(int *numkeys)
    2.10  {
    2.11      SDL_Keyboard *keyboard = &SDL_keyboard;