Re: SWIG: Bug with 'C' arrays of zero size ?
Terry Barnaby <[email protected]>
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <[email protected]> |
Actually when used as a structure member the "char data[]" defines a zero length array of chars. It is not a pointer to some other memory location. Normally used to define a data structure with a variable sized data area like a variable length network packet. Not sure what SWIG should do with this though, probably return an error but it shouldn't expect it to be a pointer. Terry On 15/06/2020 07:41, Arnaud RICHARD wrote: > As far as I know, in C data[] is not defining a 0-sized array but a pointer equivalent to *data with a hint for the reader that the pointer will be used for an array. > Considering this, SWIG behavior seems correct. > > Arnaud > >> -----Original Message----- >> From: Alberto Luaces <[email protected]> >> Sent: Saturday, June 13, 2020 10:31 >> To: [email protected] >> Subject: Re: [Swig-user] SWIG: Bug with 'C' arrays of zero size ? >> >> On Fri, Jun 12, 2020, at 10:37, Terry Barnaby wrote: >>> Hi, >>> >>> If you have a data structure like the following all is well: >>> >>> struct DataBlock { >>> Header header; >>> char data[4]; ///< The packet data }; >>> >>> However if you have a data structure that has a zero length array like >>> the following, SWIG considers the "char data[]" as a pointed to data >>> and tries to delete[] and allocate memory for it. >>> >>> struct DataBlock { >>> Header header; >>> char data[]; ///< The packet data }; >>> >>> I think this is a bug ? >> Are you using C++? It seems that zero-sized arrays are not allowed: >> >> https://stackoverflow.com/questions/6180012/array-with-size-0#6180200 >> >> >> _______________________________________________ >> Swig-user mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/swig-user > _______________________________________________ > Swig-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/swig-user _______________________________________________ Swig-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/swig-user