diff options
author | Chris Robinson <[email protected]> | 2022-04-22 11:24:39 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2022-04-22 11:24:39 -0700 |
commit | e7a2c0af762e19c336447e2034ee7ed81f111009 (patch) | |
tree | 559fefdaf0b59743c8cab19d0cdd0f355247c3b2 /examples | |
parent | 1050428d3d463616c622d3f95effa313bf334249 (diff) |
Define FUNCTION_CAST in a common header
Diffstat (limited to 'examples')
-rw-r--r-- | examples/alconvolve.c | 11 | ||||
-rw-r--r-- | examples/alhrtf.c | 2 | ||||
-rw-r--r-- | examples/allatency.c | 11 | ||||
-rw-r--r-- | examples/alloopback.c | 2 | ||||
-rw-r--r-- | examples/almultireverb.c | 11 | ||||
-rw-r--r-- | examples/alreverb.c | 11 | ||||
-rw-r--r-- | examples/common/alhelpers.h | 13 |
7 files changed, 15 insertions, 46 deletions
diff --git a/examples/alconvolve.c b/examples/alconvolve.c index 8979e7a3..93fd2eb4 100644 --- a/examples/alconvolve.c +++ b/examples/alconvolve.c @@ -84,17 +84,6 @@ static LPALGETAUXILIARYEFFECTSLOTIV alGetAuxiliaryEffectSlotiv; static LPALGETAUXILIARYEFFECTSLOTF alGetAuxiliaryEffectSlotf; static LPALGETAUXILIARYEFFECTSLOTFV alGetAuxiliaryEffectSlotfv; -/* C doesn't allow casting between function and non-function pointer types, so - * with C99 we need to use a union to reinterpret the pointer type. Pre-C99 - * still needs to use a normal cast and live with the warning (C++ is fine with - * a regular reinterpret_cast). - */ -#if __STDC_VERSION__ >= 199901L -#define FUNCTION_CAST(T, ptr) (union{void *p; T f;}){ptr}.f -#else -#define FUNCTION_CAST(T, ptr) (T)(ptr) -#endif - /* This stuff defines a simple streaming player object, the same as alstream.c. * Comments are removed for brevity, see alstream.c for more details. diff --git a/examples/alhrtf.c b/examples/alhrtf.c index b8fc287f..d878870e 100644 --- a/examples/alhrtf.c +++ b/examples/alhrtf.c @@ -170,7 +170,7 @@ int main(int argc, char **argv) } /* Define a macro to help load the function pointers. */ -#define LOAD_PROC(d, T, x) ((x) = (T)alcGetProcAddress((d), #x)) +#define LOAD_PROC(d, T, x) ((x) = FUNCTION_CAST(T, alcGetProcAddress((d), #x))) LOAD_PROC(device, LPALCGETSTRINGISOFT, alcGetStringiSOFT); LOAD_PROC(device, LPALCRESETDEVICESOFT, alcResetDeviceSOFT); #undef LOAD_PROC diff --git a/examples/allatency.c b/examples/allatency.c index 3b141ac0..ab4a4ebc 100644 --- a/examples/allatency.c +++ b/examples/allatency.c @@ -51,17 +51,6 @@ static LPALGETSOURCEI64SOFT alGetSourcei64SOFT; static LPALGETSOURCE3I64SOFT alGetSource3i64SOFT; static LPALGETSOURCEI64VSOFT alGetSourcei64vSOFT; -/* C doesn't allow casting between function and non-function pointer types, so - * with C99 we need to use a union to reinterpret the pointer type. Pre-C99 - * still needs to use a normal cast and live with the warning (C++ is fine with - * a regular reinterpret_cast). - */ -#if __STDC_VERSION__ >= 199901L -#define FUNCTION_CAST(T, ptr) (union{void *p; T f;}){ptr}.f -#else -#define FUNCTION_CAST(T, ptr) (T)(ptr) -#endif - /* LoadBuffer loads the named audio file into an OpenAL buffer object, and * returns the new buffer ID. */ diff --git a/examples/alloopback.c b/examples/alloopback.c index 844efa74..7513458b 100644 --- a/examples/alloopback.c +++ b/examples/alloopback.c @@ -149,7 +149,7 @@ int main(int argc, char *argv[]) } /* Define a macro to help load the function pointers. */ -#define LOAD_PROC(T, x) ((x) = (T)alcGetProcAddress(NULL, #x)) +#define LOAD_PROC(T, x) ((x) = FUNCTION_CAST(T, alcGetProcAddress(NULL, #x))) LOAD_PROC(LPALCLOOPBACKOPENDEVICESOFT, alcLoopbackOpenDeviceSOFT); LOAD_PROC(LPALCISRENDERFORMATSUPPORTEDSOFT, alcIsRenderFormatSupportedSOFT); LOAD_PROC(LPALCRENDERSAMPLESSOFT, alcRenderSamplesSOFT); diff --git a/examples/almultireverb.c b/examples/almultireverb.c index 447216d1..a77cc59e 100644 --- a/examples/almultireverb.c +++ b/examples/almultireverb.c @@ -92,17 +92,6 @@ static LPALGETAUXILIARYEFFECTSLOTIV alGetAuxiliaryEffectSlotiv; static LPALGETAUXILIARYEFFECTSLOTF alGetAuxiliaryEffectSlotf; static LPALGETAUXILIARYEFFECTSLOTFV alGetAuxiliaryEffectSlotfv; -/* C doesn't allow casting between function and non-function pointer types, so - * with C99 we need to use a union to reinterpret the pointer type. Pre-C99 - * still needs to use a normal cast and live with the warning (C++ is fine with - * a regular reinterpret_cast). - */ -#if __STDC_VERSION__ >= 199901L -#define FUNCTION_CAST(T, ptr) (union{void *p; T f;}){ptr}.f -#else -#define FUNCTION_CAST(T, ptr) (T)(ptr) -#endif - /* LoadEffect loads the given initial reverb properties into the given OpenAL * effect object, and returns non-zero on success. diff --git a/examples/alreverb.c b/examples/alreverb.c index 0d62e210..11a3ac6b 100644 --- a/examples/alreverb.c +++ b/examples/alreverb.c @@ -67,17 +67,6 @@ static LPALGETAUXILIARYEFFECTSLOTIV alGetAuxiliaryEffectSlotiv; static LPALGETAUXILIARYEFFECTSLOTF alGetAuxiliaryEffectSlotf; static LPALGETAUXILIARYEFFECTSLOTFV alGetAuxiliaryEffectSlotfv; -/* C doesn't allow casting between function and non-function pointer types, so - * with C99 we need to use a union to reinterpret the pointer type. Pre-C99 - * still needs to use a normal cast and live with the warning (C++ is fine with - * a regular reinterpret_cast). - */ -#if __STDC_VERSION__ >= 199901L -#define FUNCTION_CAST(T, ptr) (union{void *p; T f;}){ptr}.f -#else -#define FUNCTION_CAST(T, ptr) (T)(ptr) -#endif - /* LoadEffect loads the given reverb properties into a new OpenAL effect * object, and returns the new effect ID. */ diff --git a/examples/common/alhelpers.h b/examples/common/alhelpers.h index 3752d218..34f73864 100644 --- a/examples/common/alhelpers.h +++ b/examples/common/alhelpers.h @@ -18,6 +18,19 @@ void CloseAL(void); int altime_get(void); void al_nssleep(unsigned long nsec); +/* C doesn't allow casting between function and non-function pointer types, so + * with C99 we need to use a union to reinterpret the pointer type. Pre-C99 + * still needs to use a normal cast and live with the warning (C++ is fine with + * a regular reinterpret_cast). + */ +#if __STDC_VERSION__ >= 199901L +#define FUNCTION_CAST(T, ptr) (union{void *p; T f;}){ptr}.f +#elif defined(__cplusplus) +#define FUNCTION_CAST(T, ptr) reinterpret_cast<T>(ptr) +#else +#define FUNCTION_CAST(T, ptr) (T)(ptr) +#endif + #ifdef __cplusplus } // extern "C" #endif |