SDL_power.c: Adjust SDL_POWER_DISABLED ifdefs to avoid zero-size array
authorOzkan Sezer <sezeroz@gmail.com>
Mon, 15 Oct 2018 11:01:00 +0300
changeset 1233143d46306c3ba
parent 12330 cf64a70ad02a
child 12332 c80f702e4b8b
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
OWMakefile.os2
include/SDL_config_os2.h
src/power/SDL_power.c
     1.1 --- a/OWMakefile.os2	Mon Oct 15 00:46:43 2018 -0400
     1.2 +++ b/OWMakefile.os2	Mon Oct 15 11:01:00 2018 +0300
     1.3 @@ -19,15 +19,6 @@
     1.4  # building SDL itself:
     1.5  CFLAGS+= -DBUILD_SDL
     1.6  
     1.7 -# this is so that build doesn't fail with E1112:
     1.8 -#CFLAGS+= -DSDL_POWER_DISABLED
     1.9 -CFLAGS+= -DSDL_POWER_HARDWIRED
    1.10 -
    1.11 -.extensions:
    1.12 -.extensions: .lib .dll .obj .c .asm
    1.13 -
    1.14 -.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;
    1.15 -
    1.16  SRCS = SDL.c SDL_assert.c SDL_error.c SDL_log.c SDL_dataqueue.c SDL_hints.c
    1.17  SRCS+= SDL_getenv.c SDL_iconv.c SDL_malloc.c SDL_qsort.c SDL_stdlib.c SDL_string.c
    1.18  SRCS+= SDL_cpuinfo.c SDL_atomic.c SDL_spinlock.c SDL_thread.c SDL_timer.c
    1.19 @@ -58,6 +49,11 @@
    1.20  
    1.21  OBJS = $(SRCS:.c=.obj)
    1.22  
    1.23 +.extensions:
    1.24 +.extensions: .lib .dll .obj .c .asm
    1.25 +
    1.26 +.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;
    1.27 +
    1.28  all: $(DLLFILE) $(LIBFILE) .symbolic
    1.29  
    1.30  $(DLLFILE): $(OBJS) $(LNKFILE)
     2.1 --- a/include/SDL_config_os2.h	Mon Oct 15 00:46:43 2018 -0400
     2.2 +++ b/include/SDL_config_os2.h	Mon Oct 15 11:01:00 2018 +0300
     2.3 @@ -28,6 +28,7 @@
     2.4  #define SDL_AUDIO_DRIVER_DUMMY 1
     2.5  #define SDL_AUDIO_DRIVER_DISK 1
     2.6  
     2.7 +#define SDL_POWER_DISABLED  1
     2.8  #define SDL_JOYSTICK_DISABLED 1
     2.9  #define SDL_HAPTIC_DISABLED 1
    2.10  /*#undef SDL_JOYSTICK_HIDAPI */
     3.1 --- a/src/power/SDL_power.c	Mon Oct 15 00:46:43 2018 -0400
     3.2 +++ b/src/power/SDL_power.c	Mon Oct 15 11:01:00 2018 +0300
     3.3 @@ -42,11 +42,8 @@
     3.4      return SDL_TRUE;
     3.5  }
     3.6  #endif
     3.7 -#endif
     3.8 -
     3.9  
    3.10  static SDL_GetPowerInfo_Impl implementations[] = {
    3.11 -#ifndef SDL_POWER_DISABLED
    3.12  #ifdef SDL_POWER_LINUX          /* in order of preference. More than could work. */
    3.13      SDL_GetPowerInfo_Linux_org_freedesktop_upower,
    3.14      SDL_GetPowerInfo_Linux_sys_class_power_supply,
    3.15 @@ -81,31 +78,34 @@
    3.16  #ifdef SDL_POWER_HARDWIRED
    3.17      SDL_GetPowerInfo_Hardwired,
    3.18  #endif
    3.19 +};
    3.20  #endif
    3.21 -};
    3.22  
    3.23  SDL_PowerState
    3.24  SDL_GetPowerInfo(int *seconds, int *percent)
    3.25  {
    3.26 +#ifndef SDL_POWER_DISABLED
    3.27      const int total = sizeof(implementations) / sizeof(implementations[0]);
    3.28 -    int _seconds, _percent;
    3.29      SDL_PowerState retval = SDL_POWERSTATE_UNKNOWN;
    3.30      int i;
    3.31 +#endif
    3.32  
    3.33 +    int _seconds, _percent;
    3.34      /* Make these never NULL for platform-specific implementations. */
    3.35      if (seconds == NULL) {
    3.36          seconds = &_seconds;
    3.37      }
    3.38 -
    3.39      if (percent == NULL) {
    3.40          percent = &_percent;
    3.41      }
    3.42  
    3.43 +#ifndef SDL_POWER_DISABLED
    3.44      for (i = 0; i < total; i++) {
    3.45          if (implementations[i](&retval, seconds, percent)) {
    3.46              return retval;
    3.47          }
    3.48      }
    3.49 +#endif
    3.50  
    3.51      /* nothing was definitive. */
    3.52      *seconds = -1;