[AD] ALLEGRO_KEYBOARD_STATE improvement

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


In the Allegro source, there is this construct:

typedef struct ALLEGRO_KEYBOARD_STATE
{
   struct ALLEGRO_DISPLAY *display;  /* public */
   unsigned int __key_down__internal__[4]; /* internal */
   /* Was using uint32_t, but some machines don't have stdint.h. */
#if AL_KEY_MAX >= (32 * 4)
# error __key_down__internal__ array not big enough for AL_KEY_MAX
#endif
} ALLEGRO_KEYBOARD_STATE;

Obviously, AL_KEY_MAX isn't the right symbol to use. However, since
ALLEGRO_KEY_MAX is no longer a preprocessor symbol at all, that error
will never get triggered. I've written a patch that changes the size
of the array to be statically calculated using the value of
ALLEGRO_KEY_MAX:

typedef struct ALLEGRO_KEYBOARD_STATE
{
   struct ALLEGRO_DISPLAY *display;  /* public */
   unsigned int __key_down__internal__[(ALLEGRO_KEY_MAX + 7) / 8 /
sizeof(unsigned int)]; /* internal */
   /* Was using uint32_t, but some machines don't have stdint.h. */
} ALLEGRO_KEYBOARD_STATE;

No other files need to be changed.

-- 
Regards,
Ryan Patterson <mailto:cgamesplay@xxxxxxxxxx>
Index: include/allegro5/keyboard.h
===================================================================
--- include/allegro5/keyboard.h	(revision 11075)
+++ include/allegro5/keyboard.h	(working copy)
@@ -50,11 +50,8 @@
 typedef struct ALLEGRO_KEYBOARD_STATE
 {
    struct ALLEGRO_DISPLAY *display;  /* public */
-   unsigned int __key_down__internal__[4]; /* internal */
-   /* Was using uint32_t, but some machines don't have stdint.h. */ 
-#if AL_KEY_MAX >= (32 * 4)
-# error __key_down__internal__ array not big enough for AL_KEY_MAX
-#endif
+   unsigned int __key_down__internal__[(ALLEGRO_KEY_MAX + 7) / 8 / sizeof(unsigned int)]; /* internal */
+   /* Was using uint32_t, but some machines don't have stdint.h. */
 } ALLEGRO_KEYBOARD_STATE;
 
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/