diff options
author | Chris Robinson <[email protected]> | 2012-02-19 12:07:40 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2012-02-19 12:07:40 -0800 |
commit | 4a65747a4b20cbbfb2627bf10ded6f5b897cb908 (patch) | |
tree | 9a8c3bc309514340dd8795db8904fe51fd8d3803 | |
parent | 6dc194ed1defc358c9ed4ee8a67db71f5c040766 (diff) |
Add a COUNTOF macro to get the number of entries in a static array
-rw-r--r-- | Alc/ALc.c | 14 | ||||
-rw-r--r-- | Alc/backends/alsa.c | 4 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 1 | ||||
-rw-r--r-- | OpenAL32/alBuffer.c | 4 | ||||
-rw-r--r-- | OpenAL32/alEffect.c | 2 |
5 files changed, 13 insertions, 12 deletions
@@ -970,7 +970,7 @@ static ALboolean DecomposeDevFormat(ALenum format, enum DevFmtChannels *chans, }; ALuint i; - for(i = 0;i < sizeof(list)/sizeof(list[0]);i++) + for(i = 0;i < COUNTOF(list);i++) { if(list[i].format == format) { @@ -2474,7 +2474,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) }; size_t i; - for(i = 0;i < sizeof(chanlist)/sizeof(chanlist[0]);i++) + for(i = 0;i < COUNTOF(chanlist);i++) { if(strcasecmp(chanlist[i].name, fmt) == 0) { @@ -2483,7 +2483,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) break; } } - if(i == sizeof(chanlist)/sizeof(chanlist[0])) + if(i == COUNTOF(chanlist)) ERR("Unsupported channels: %s\n", fmt); } if(ConfigValueStr(NULL, "sample-type", &fmt)) @@ -2502,7 +2502,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) }; size_t i; - for(i = 0;i < sizeof(typelist)/sizeof(typelist[0]);i++) + for(i = 0;i < COUNTOF(typelist);i++) { if(strcasecmp(typelist[i].name, fmt) == 0) { @@ -2511,7 +2511,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) break; } } - if(i == sizeof(typelist)/sizeof(typelist[0])) + if(i == COUNTOF(typelist)) ERR("Unsupported sample-type: %s\n", fmt); } #define DEVICE_FORMAT_REQUEST (DEVICE_CHANNELS_REQUEST|DEVICE_SAMPLE_TYPE_REQUEST) @@ -2547,7 +2547,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) size_t i; ERR("Option 'format' is deprecated, please use 'channels' and 'sample-type'\n"); - for(i = 0;i < sizeof(formats)/sizeof(formats[0]);i++) + for(i = 0;i < COUNTOF(formats);i++) { if(strcasecmp(fmt, formats[i].name) == 0) { @@ -2559,7 +2559,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) break; } } - if(i == sizeof(formats)/sizeof(formats[0])) + if(i == COUNTOF(formats)) ERR("Unsupported format: %s\n", fmt); } #undef DEVICE_FORMAT_REQUEST diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index 51579750..9f77b60d 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -703,7 +703,7 @@ static ALCboolean alsa_reset_playback(ALCdevice *device) }; size_t k; - for(k = 0;k < sizeof(formatlist)/sizeof(formatlist[0]);k++) + for(k = 0;k < COUNTOF(formatlist);k++) { format = formatlist[k].format; if(snd_pcm_hw_params_test_format(data->pcmHandle, p, format) >= 0) @@ -726,7 +726,7 @@ static ALCboolean alsa_reset_playback(ALCdevice *device) }; size_t k; - for(k = 0;k < sizeof(channellist)/sizeof(channellist[0]);k++) + for(k = 0;k < COUNTOF(channellist);k++) { if(snd_pcm_hw_params_test_channels(data->pcmHandle, p, ChannelsFromDevFmt(channellist[k])) >= 0) { diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 8427f83b..490721be 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -105,6 +105,7 @@ static const union { } EndianTest = { 1 }; #define IS_LITTLE_ENDIAN (EndianTest.b[0] == 1) +#define COUNTOF(x) (sizeof((x))/sizeof((x)[0])) #ifdef _WIN32 diff --git a/OpenAL32/alBuffer.c b/OpenAL32/alBuffer.c index 6a3bb114..5a0e1dee 100644 --- a/OpenAL32/alBuffer.c +++ b/OpenAL32/alBuffer.c @@ -2136,7 +2136,7 @@ static ALboolean DecomposeUserFormat(ALenum format, enum UserFmtChannels *chans, }; ALuint i; - for(i = 0;i < sizeof(list)/sizeof(list[0]);i++) + for(i = 0;i < COUNTOF(list);i++) { if(list[i].format == format) { @@ -2213,7 +2213,7 @@ static ALboolean DecomposeFormat(ALenum format, enum FmtChannels *chans, enum Fm }; ALuint i; - for(i = 0;i < sizeof(list)/sizeof(list[0]);i++) + for(i = 0;i < COUNTOF(list);i++) { if(list[i].format == format) { diff --git a/OpenAL32/alEffect.c b/OpenAL32/alEffect.c index 4e04089c..aebda3c7 100644 --- a/OpenAL32/alEffect.c +++ b/OpenAL32/alEffect.c @@ -1449,7 +1449,7 @@ static const struct { DECL(SMALLWATERROOM), }; #undef DECL -static const ALsizei reverblistsize = sizeof(reverblist)/sizeof(reverblist[0]); +static const ALsizei reverblistsize = COUNTOF(reverblist); ALvoid GetReverbEffect(const char *name, ALeffect *effect) { |