From cb216b4c96a370bf5005b212919aeef87446d8fe Mon Sep 17 00:00:00 2001 From: Chris Dickens Date: Wed, 5 Jul 2017 13:09:29 -0700 Subject: [PATCH] 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 --- libusb/libusb.h | 30 +++++++++--------------------- libusb/libusbi.h | 23 ++++------------------- libusb/version_nano.h | 2 +- 3 files changed, 14 insertions(+), 41 deletions(-) diff --git a/libusb/libusb.h b/libusb/libusb.h index f0f6d71..70ee2ca 100644 --- a/libusb/libusb.h +++ b/libusb/libusb.h @@ -61,6 +61,12 @@ typedef unsigned __int32 uint32_t; #include #include +#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 diff --git a/libusb/libusbi.h b/libusb/libusbi.h index 026ed0f..3ae4635 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -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( diff --git a/libusb/version_nano.h b/libusb/version_nano.h index f2515f9..90736cc 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11203 +#define LIBUSB_NANO 11204 -- 2.7.4