1

Super quick question, my initial thought was this is not going to work, but then I thought why not give it a go. Now I am thinking it won't work as the resultant array does not seem to be properly formed? My question, should this work?

NSUInteger numPoints = [[[self dataModel] locationFake] count];
CLLocationCoordinate2D points[numPoints];
3
  • My question: Why not just try it? Commented Jan 20, 2011 at 17:53
  • I did try it and could not get it to work, I then spotted it in some other code online and that started me thinking. I was pretty sure it would not work, and half expected to get a compile error. But like I say the example online got me thinking ... Commented Jan 20, 2011 at 17:57
  • 2nd block of code, lines 2 & 3: blog.trentkocurek.com/… Commented Jan 20, 2011 at 17:58

1 Answer 1

4

No, it wouldn't work as the points[] array needs to be sized statically. That is, the compiler needs to know the size of that array, but can't possibly know it until runtime.

If you change it to:

CLLocationCoordinate2D *points = malloc(numPoints * sizeof(CLLocationCoordinate2D));

That should work. Just don't forget to free() it later when you are done.

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

1 Comment

Thank you, that was the way I was going, but just wanted to check. Much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.