Ticket #2 (new defect)
ISO C++ forbids zero-size array 'iso_packet_desc'
| Reported by: | dsd | Owned by: | |
|---|---|---|---|
| Component: | libusb-1.0 | Keywords: | |
| Cc: | Blocked By: | ||
| Blocks: |
Description
from: https://sourceforge.net/tracker/?func=detail&aid=2740374&group_id=1674&atid=101674
libusb.h causes errors in C++ projects that use GCC's -pedantic switch:
error: ISO C++ forbids zero-size array 'iso_packet_desc'
One solution is to make the array size 1 and account for that change in all places that use sizeof(struct libusb_transfer), e.g.: int alloc_size = sizeof(struct usbi_transfer) + sizeof(struct libusb_transfer) + (sizeof(struct libusb_iso_packet_descriptor) * (iso_packets-1)) + os_alloc_size;
OK. Then I have a possible solution which I don't completely dislike: use an #ifdef to make the array size 1 when using a C++ compiler, but leave the other situations as-is. Outside of the header file, no libusb changes are needed since libusb will always be compiled with a C compiler. What do you think?
Change History
comment:2 Changed 7 months ago by hansdegoede
Using 0 sized arrays at the end of a struct for a variable sized array is quite a normal thing to-do now a days in plain C.
Since this is only a warning and only happens with -pedantic, and likely only with older gcc versions I suggest we just close this one. Also note that the proposed fix would be an ABI change which is a no no.
Note: See
TracTickets for help on using
tickets.
Just wondering how to reproduce this one and wonder if this is valid or not.
mcuee@ubuntu:~/Desktop/build/libusb1/test$ g++ -pedantic test.cpp -o test -lusb-1.0
mcuee@ubuntu:~/Desktop/build/libusb1/test$ cat test.cpp
#include <libusb-1.0/libusb.h>
#include <iostream>
using namespace std;
int main()
{
using libusb.h
";
}
mcuee@ubuntu:~/Desktop/build/libusb1/test$ g++ -pedantic test.cpp -o test -lusb-1.0
mcuee@ubuntu:~/Desktop/build/libusb1/test$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)