Re: SWIG: Bug with 'C' arrays of zero size ?

Terry Barnaby <[email protected]>
Newsgroups gmane.comp.programming.swig
Message-ID <[email protected]>
On 27/06/2020 09:58, William S Fulton wrote:
>
>
> On Fri, 12 Jun 2020 at 09:37, Terry Barnaby <[email protected] 
> <mailto:[email protected]>> 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 ?
>
>
> Hi Terry
>
> This is a pointer to an undetermined array of char characters. By 
> default SWIG chooses to wrap this a pointer to a NULL terminated array 
> of characters, that is, a string. There is no bug here!
>
> You can use typemaps to change the behaviour to whatever you want.
>
> William
>
But actually the data member is not a pointer to an array of characters, 
the actual array is contained within the structures memory area as part 
of the data structure (although 0 length!). So I would have though that 
SWIG should handle this just as if you had a size to this. Admittedly 
this is probably mute as you may not be able to wrap that member 
correctly in SWIG anyway :)

Terry

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.