Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4112118
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:09:15+00:00 2026-05-20T22:09:15+00:00

Blocks are fine but what about writing C arrays? Given this simplified situation: CGPoint

  • 0

Blocks are fine but what about writing C arrays?

Given this simplified situation:

CGPoint points[10];
[myArray forEachElementWithBlock:^(int idx) {
    points[idx] = CGPointMake(10, 20); // error here
    // Cannot refer to declaration with an array type inside block
}];

after searching a while found this possible solution, to put it in a struct:

__block struct {
    CGPoint points[100];
} pointStruct;

[myArray forEachElementWithBlock:^(int idx) {
    pointStruct.points[idx] = CGPointMake(10, 20);
}];

this would work but there is a little limitation I have to create the c array dynamically:

int count = [str countOccurencesOfString:@";"];
__block struct {
    CGPoint points[count]; // error here
    // Fields must have a constant size: 'variable length array in structure' extension will never be supported
} pointStruct;

How can I access my CGPoint array within a block?

OR

Is it even possible at all or do I have to rewrite the block method to get the full functionality?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:09:16+00:00Added an answer on May 20, 2026 at 10:09 pm

    Maybe you can allocate the array on the heap?

    // Allocates a plain C array on the heap. The array will have
    // [myArray count] items, each sized to fit a CGPoint.
    CGPoint *points = calloc([myArray count], sizeof(CGPoint));
    // Make sure the allocation succeded, you might want to insert
    // some more graceful error handling here.
    NSParameterAssert(points != NULL);
    
    // Loop over myArray, doing whatever you want
    [myArray forEachElementWithBlock:^(int idx) {
        points[idx] = …;
    }];
    
    // Free the memory taken by the C array. Of course you might
    // want to do something else with the array, otherwise this
    // excercise does not make much sense :)
    free(points), points = NULL;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My program compiles fine, but crashes everytime throw (not inside of a try...catch block)
if i remove a.three display block this shows up fine. However what i want
I hate blocks. They are meant to make the code more concise, but I
I'm writing a Linux program that currently compiles and works fine on x86 and
I know this has been discussed ad nauseum...but I have an issue with the
This may be a stupid question, but I'm interested in the performance of using
I happened to ask myself a question about arrays in c++. Well, we all
This may be something I just have to live with, but does the blockUI
I have read many articles about vertical centering but I’m afraid not many of
I'm writing a C++ Package for later use using Code::Blocks. The project structure looks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.