Re: How to store C Arrays as a Property or iVar?


Dave
 

Hi Jens,

You solved two problem in one with your last post - thanks a lot!

I had some other information that was being passed back and forth and creating a structure allowed me to solve the Array copying problem and I could add the extra information fields to the struct!

Thanks again,
All the Best
Dave

On 18 Aug 2017, at 22:04, Jens Alfke <jens@...> wrote:


On Aug 18, 2017, at 12:07 PM, Dave <dave@...> wrote:

But I get an error if I try to assign or read it, as in:

myArray = _mArray;

You can't assign (or compare) arrays in C/C++. You have two options:

(a) Call memcpy:
memcpy(&myArray, &_mArray, sizeof(myArray));

(b) Wrap a struct around the array, since structs are copyable. Drawback is that you now have to refer to the array as a named field of the struct.
typedef struct {
int [10][10]  a;
} MyArrayType;
MyArrayType myArray;
_mArray = myArray;

(This is a pure C issue, so a book like K&R would be helpful.)

—Jens

Join cocoa@apple-dev.groups.io to automatically receive all group messages.