0

I'm using a C library in my Swift 3 application. One of the structs defined in the library is defined thusly:

struct termRow {
    void *bitmaps[BITMAP_PTRS];
    int flags;
    uint64_t chars[];
};

In my Swift code, when I reference a property of this termRow type, I have access to the bitmaps and flags, but the chars array is nowhere to be found! In Xcode, the autocomplete tells the story -- no chars value:

enter image description here

My assumption here is that Swift is unable to translate uint64_t arrays? If that is the case, what can I do to make it work in my Swift code, without screwing things up for the rest of the library?

2
  • 1
    Maybe it just doesn't like the flexible array member. Commented Jul 1, 2017 at 2:42
  • What's the library? Do you have the full headers for it? Have you tried using it in a C, C++, or Objective-C program? Commented Jul 1, 2017 at 5:34

1 Answer 1

1

I assume from the image that your row variable is a local instance of struct termRow. Are you sure the chars array was initialized? An array at the end of a struct with no defined bounds is an array of indeterminate length; If it is not initialized (in the case of a local) or allocated (in the case of a pointer), then it technically doesn't exist. Maybe that's what Xcode is trying to tell you.

Sign up to request clarification or add additional context in comments.

2 Comments

Indeed, giving the array a size makes it show up. Alas! Thanks.
No sweat. Note also that "indeterminate" doesn't mean "variable". Once the array is bounded, either through initialization or allocation, the size is fixed from that point on for a given instance.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.