From f9693f7ea2a42ea2198327d42ff05b9e6dc4b38a Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 26 Oct 2012 23:15:34 +0200 Subject: [PATCH] ARRAY_SIZE to simplify some for-loops. --- driver.c | 12 ++++++------ general.h | 1 + settings.c | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/driver.c b/driver.c index b8883e1563..b6918f0620 100644 --- a/driver.c +++ b/driver.c @@ -149,7 +149,7 @@ static const input_driver_t *input_drivers[] = { static void find_audio_driver(void) { - for (unsigned i = 0; i < sizeof(audio_drivers) / sizeof(audio_driver_t*); i++) + for (unsigned i = 0; i < ARRAY_SIZE(audio_drivers); i++) { if (strcasecmp(g_settings.audio.driver, audio_drivers[i]->ident) == 0) { @@ -159,7 +159,7 @@ static void find_audio_driver(void) } RARCH_ERR("Couldn't find any audio driver named \"%s\"\n", g_settings.audio.driver); RARCH_LOG_OUTPUT("Available audio drivers are:\n"); - for (size_t i = 0; i < sizeof(audio_drivers) / sizeof(audio_driver_t*); i++) + for (size_t i = 0; i < ARRAY_SIZE(audio_drivers); i++) RARCH_LOG_OUTPUT("\t%s\n", audio_drivers[i]->ident); rarch_fail(1, "find_audio_driver()"); @@ -167,7 +167,7 @@ static void find_audio_driver(void) static void find_video_driver(void) { - for (unsigned i = 0; i < sizeof(video_drivers) / sizeof(video_driver_t*); i++) + for (unsigned i = 0; i < ARRAY_SIZE(video_drivers); i++) { if (strcasecmp(g_settings.video.driver, video_drivers[i]->ident) == 0) { @@ -177,7 +177,7 @@ static void find_video_driver(void) } RARCH_ERR("Couldn't find any video driver named \"%s\"\n", g_settings.video.driver); RARCH_LOG_OUTPUT("Available video drivers are:\n"); - for (size_t i = 0; i < sizeof(video_drivers) / sizeof(video_driver_t*); i++) + for (size_t i = 0; i < ARRAY_SIZE(video_drivers); i++) RARCH_LOG_OUTPUT("\t%s\n", video_drivers[i]->ident); rarch_fail(1, "find_video_driver()"); @@ -185,7 +185,7 @@ static void find_video_driver(void) static void find_input_driver(void) { - for (unsigned i = 0; i < sizeof(input_drivers) / sizeof(input_driver_t*); i++) + for (unsigned i = 0; i < ARRAY_SIZE(input_drivers); i++) { if (strcasecmp(g_settings.input.driver, input_drivers[i]->ident) == 0) { @@ -195,7 +195,7 @@ static void find_input_driver(void) } RARCH_ERR("Couldn't find any input driver named \"%s\"\n", g_settings.input.driver); RARCH_LOG_OUTPUT("Available input drivers are:\n"); - for (size_t i = 0; i < sizeof(input_drivers) / sizeof(input_driver_t*); i++) + for (size_t i = 0; i < ARRAY_SIZE(input_drivers); i++) RARCH_LOG_OUTPUT("\t%s\n", input_drivers[i]->ident); rarch_fail(1, "find_input_driver()"); diff --git a/general.h b/general.h index 69e604526b..7825cc07c0 100644 --- a/general.h +++ b/general.h @@ -620,6 +620,7 @@ extern struct global g_extern; #define min(a, b) ((a) < (b) ? (a) : (b)) #endif +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #define RARCH_SCALE_BASE 256 static inline uint32_t next_pow2(uint32_t v) diff --git a/settings.c b/settings.c index aada7efae0..fc2095136c 100644 --- a/settings.c +++ b/settings.c @@ -766,7 +766,7 @@ static struct retro_keybind *find_retro_bind(unsigned port, int id) static int find_sk_bind(const char *str) { - for (size_t i = 0; i < sizeof(sk_map) / sizeof(struct key_map); i++) + for (size_t i = 0; i < ARRAY_SIZE(sk_map); i++) { if (strcasecmp(sk_map[i].str, str) == 0) return sk_map[i].key; @@ -903,7 +903,7 @@ static void save_keybind_key(config_file_t *conf, ascii[0] = 'a' + (bind->key - RETROK_a); else { - for (unsigned i = 0; i < sizeof(sk_map) / sizeof(sk_map[0]); i++) + for (unsigned i = 0; i < ARRAY_SIZE(sk_map); i++) { if (sk_map[i].key == bind->key) {