From 8b960d4e0f466c7b8abc1e60752867818b6b92b5 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 6 Dec 2016 02:20:58 -0500 Subject: [PATCH] Added SDL_VARIABLE_LENGTH_ARRAY so this #ifdef is localized to one place. --- src/SDL_internal.h | 9 +++++++++ src/audio/SDL_sysaudio.h | 6 +----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/SDL_internal.h b/src/SDL_internal.h index b0587f679dd63..d810740a74818 100644 --- a/src/SDL_internal.h +++ b/src/SDL_internal.h @@ -26,6 +26,15 @@ #define _GNU_SOURCE #endif +/* This is for a variable-length array at the end of a struct: + struct x { int y; char z[SDL_VARIABLE_LENGTH_ARRAY]; }; + Use this because GCC 2 needs different magic than other compilers. */ +#if (defined(__GNUC__) && (__GNUC__ <= 2)) +#define SDL_VARIABLE_LENGTH_ARRAY 1 +#else +#define SDL_VARIABLE_LENGTH_ARRAY +#endif + #include "dynapi/SDL_dynapi.h" #if SDL_DYNAMIC_API diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h index 007f182f40744..a5574c503f74d 100644 --- a/src/audio/SDL_sysaudio.h +++ b/src/audio/SDL_sysaudio.h @@ -105,11 +105,7 @@ typedef struct SDL_AudioDeviceItem { void *handle; struct SDL_AudioDeviceItem *next; - #if (defined(__GNUC__) && (__GNUC__ <= 2)) - char name[1]; /* actually variable length. */ - #else - char name[]; - #endif + char name[SDL_VARIABLE_LENGTH_ARRAY]; } SDL_AudioDeviceItem;