SDL_power.c: Adjust SDL_POWER_DISABLED ifdefs to avoid zero-size array

Otherwise if SDL_POWER_DISABLED is disabled (eg with --disable-power):

... with clang -pedantic:
src/power/SDL_power.c:48:50: warning: use of GNU empty initializer extension [-Wgnu-empty-initializer]
static SDL_GetPowerInfo_Impl implementations[] = {
                                                 ^
src/power/SDL_power.c:48:50: warning: zero size arrays are an extension [-Wzero-length-array]
2 warnings generated.

... with gcc -pedantic:
src/power/SDL_power.c:48:50: warning: ISO C forbids empty initializer braces [-Wpedantic]
src/power/SDL_power.c:48:50: warning: ISO C forbids empty initializer braces [-Wpedantic]
 static SDL_GetPowerInfo_Impl implementations[] = {
                                                  ^
src/power/SDL_power.c:48:30: error: zero or negative size array ?implementations?
 static SDL_GetPowerInfo_Impl implementations[] = {
                              ^~~~~~~~~~~~~~~

... with Watcom:
./src/power/SDL_power.c(85): Error! E1112: Initializer list cannot be empty
This commit is contained in:
Ozkan Sezer 2018-10-15 11:01:00 +03:00
parent dae4a01361
commit 7be4fca62c
3 changed files with 12 additions and 15 deletions

View file

@ -19,15 +19,6 @@ CFLAGS+= $(INCPATH)
# building SDL itself:
CFLAGS+= -DBUILD_SDL
# this is so that build doesn't fail with E1112:
#CFLAGS+= -DSDL_POWER_DISABLED
CFLAGS+= -DSDL_POWER_HARDWIRED
.extensions:
.extensions: .lib .dll .obj .c .asm
.c: ./src;./src/dynapi;./src/audio;./src/cpuinfo;./src/events;./src/file;./src/haptic;./src/joystick;./src/power;./src/render;./src/render/software;./src/sensor;./src/stdlib;./src/thread;./src/timer;./src/video;./src/video/yuv2rgb;./src/haptic/dummy;./src/joystick/dummy;./src/loadso/dummy;./src/filesystem/dummy;./src/thread/generic;./src/timer/dummy;./src/power;./src/power/os2;./src/atomic;./src/audio/dummy;./src/audio/disk;./src/video/dummy;./src/sensor/dummy;./src/test;
SRCS = SDL.c SDL_assert.c SDL_error.c SDL_log.c SDL_dataqueue.c SDL_hints.c
SRCS+= SDL_getenv.c SDL_iconv.c SDL_malloc.c SDL_qsort.c SDL_stdlib.c SDL_string.c
SRCS+= SDL_cpuinfo.c SDL_atomic.c SDL_spinlock.c SDL_thread.c SDL_timer.c
@ -58,6 +49,11 @@ SRCS+= SDL_dynapi.c
OBJS = $(SRCS:.c=.obj)
.extensions:
.extensions: .lib .dll .obj .c .asm
.c: ./src;./src/dynapi;./src/audio;./src/cpuinfo;./src/events;./src/file;./src/haptic;./src/joystick;./src/power;./src/render;./src/render/software;./src/sensor;./src/stdlib;./src/thread;./src/timer;./src/video;./src/video/yuv2rgb;./src/haptic/dummy;./src/joystick/dummy;./src/loadso/dummy;./src/filesystem/dummy;./src/thread/generic;./src/timer/dummy;./src/power;./src/power/os2;./src/atomic;./src/audio/dummy;./src/audio/disk;./src/video/dummy;./src/sensor/dummy;./src/test;
all: $(DLLFILE) $(LIBFILE) .symbolic
$(DLLFILE): $(OBJS) $(LNKFILE)

View file

@ -28,6 +28,7 @@
#define SDL_AUDIO_DRIVER_DUMMY 1
#define SDL_AUDIO_DRIVER_DISK 1
#define SDL_POWER_DISABLED 1
#define SDL_JOYSTICK_DISABLED 1
#define SDL_HAPTIC_DISABLED 1
/*#undef SDL_JOYSTICK_HIDAPI */

View file

@ -42,11 +42,8 @@ SDL_GetPowerInfo_Hardwired(SDL_PowerState * state, int *seconds, int *percent)
return SDL_TRUE;
}
#endif
#endif
static SDL_GetPowerInfo_Impl implementations[] = {
#ifndef SDL_POWER_DISABLED
#ifdef SDL_POWER_LINUX /* in order of preference. More than could work. */
SDL_GetPowerInfo_Linux_org_freedesktop_upower,
SDL_GetPowerInfo_Linux_sys_class_power_supply,
@ -81,31 +78,34 @@ static SDL_GetPowerInfo_Impl implementations[] = {
#ifdef SDL_POWER_HARDWIRED
SDL_GetPowerInfo_Hardwired,
#endif
#endif
};
#endif
SDL_PowerState
SDL_GetPowerInfo(int *seconds, int *percent)
{
#ifndef SDL_POWER_DISABLED
const int total = sizeof(implementations) / sizeof(implementations[0]);
int _seconds, _percent;
SDL_PowerState retval = SDL_POWERSTATE_UNKNOWN;
int i;
#endif
int _seconds, _percent;
/* Make these never NULL for platform-specific implementations. */
if (seconds == NULL) {
seconds = &_seconds;
}
if (percent == NULL) {
percent = &_percent;
}
#ifndef SDL_POWER_DISABLED
for (i = 0; i < total; i++) {
if (implementations[i](&retval, seconds, percent)) {
return retval;
}
}
#endif
/* nothing was definitive. */
*seconds = -1;