using Unsized Arrays in Structures from d?
Simen Kjærås
simen.kjaras at gmail.com
Fri May 4 13:15:34 UTC 2018
On Friday, 4 May 2018 at 13:02:08 UTC, NewUser wrote:
> How can I use the following c structure from d.
>
> struct Item
> {
> int id;
> };
>
> struct Group
> {
> int i;
> int item_count;
> struct Item items[];
> };
>
> tried defining items[] as both "Item[] items" and "Item* items"
> in d, it compiles okay but gives an error when trying to access
> it.
>
> Here is the error.
> object.Error@(0): Access Violation
The D equivalent is:
struct Item {
int id;
}
struct Group {
int i;
int item_count;
Item* items;
}
The error message you're getting makes me think items is null.
The lack of function names in the stack trace makes it kinda hard
to understand exactly what's happening - you can turn that on
with -g for DMD. Seeing some of the code that uses these structs
might also help.
--
Simen
More information about the Digitalmars-d-learn
mailing list