Misc: Refactor zero-length array declarations

Instead of checking for __STDC_VERSION__ at every instance, define a
ZERO_SIZED_ARRAY macro that has the appropriate definition and use that
everywhere it is needed.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
This commit is contained in:
Chris Dickens
2017-07-05 13:09:29 -07:00
parent e59e437a1f
commit cb216b4c96
3 changed files with 14 additions and 41 deletions
+9 -21
View File
@@ -61,6 +61,12 @@ typedef unsigned __int32 uint32_t;
#include <time.h>
#include <limits.h>
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
#define ZERO_SIZED_ARRAY /* [] - valid C99 code */
#else
#define ZERO_SIZED_ARRAY 0 /* [0] - non-standard, but usually working code */
#endif
/* 'interface' might be defined as a macro on Windows, so we need to
* undefine it so as not to break the current libusb API, because
* libusb_config_descriptor has an 'interface' member
@@ -729,13 +735,7 @@ struct libusb_bos_dev_capability_descriptor {
/** Device Capability type */
uint8_t bDevCapabilityType;
/** Device Capability data (bLength - 3 bytes) */
uint8_t dev_capability_data
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
[] /* valid C99 code */
#else
[0] /* non-standard, but usually working code */
#endif
;
uint8_t dev_capability_data[ZERO_SIZED_ARRAY];
};
/** \ingroup libusb_desc
@@ -760,13 +760,7 @@ struct libusb_bos_descriptor {
uint8_t bNumDeviceCaps;
/** bNumDeviceCap Device Capability Descriptors */
struct libusb_bos_dev_capability_descriptor *dev_capability
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
[] /* valid C99 code */
#else
[0] /* non-standard, but usually working code */
#endif
;
struct libusb_bos_dev_capability_descriptor *dev_capability[ZERO_SIZED_ARRAY];
};
/** \ingroup libusb_desc
@@ -1256,13 +1250,7 @@ struct libusb_transfer {
int num_iso_packets;
/** Isochronous packet descriptors, for isochronous transfers only. */
struct libusb_iso_packet_descriptor iso_packet_desc
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
[] /* valid C99 code */
#else
[0] /* non-standard, but usually working code */
#endif
;
struct libusb_iso_packet_descriptor iso_packet_desc[ZERO_SIZED_ARRAY];
};
/** \ingroup libusb_misc
+4 -19
View File
@@ -396,12 +396,7 @@ struct libusb_device {
struct libusb_device_descriptor device_descriptor;
int attached;
unsigned char os_priv
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
[] /* valid C99 code */
#else
[0] /* non-standard, but usually working code */
#endif
unsigned char os_priv[ZERO_SIZED_ARRAY]
#if defined(OS_SUNOS)
__attribute__ ((aligned (8)));
#else
@@ -417,12 +412,8 @@ struct libusb_device_handle {
struct list_head list;
struct libusb_device *dev;
int auto_detach_kernel_driver;
unsigned char os_priv
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
[] /* valid C99 code */
#else
[0] /* non-standard, but usually working code */
#endif
unsigned char os_priv[ZERO_SIZED_ARRAY]
#if defined(OS_SUNOS)
__attribute__ ((aligned (8)));
#else
@@ -581,13 +572,7 @@ void usbi_remove_pollfd(struct libusb_context *ctx, int fd);
struct discovered_devs {
size_t len;
size_t capacity;
struct libusb_device *devices
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
[] /* valid C99 code */
#else
[0] /* non-standard, but usually working code */
#endif
;
struct libusb_device *devices[ZERO_SIZED_ARRAY];
};
struct discovered_devs *discovered_devs_append(
+1 -1
View File
@@ -1 +1 @@
#define LIBUSB_NANO 11203
#define LIBUSB_NANO 11204