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

  • Home
  • SEARCH
  • 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 8089413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:23:13+00:00 2026-06-05T19:23:13+00:00

How can I specify that a method should take as parameter a pointer to

  • 0

How can I specify that a method should take as parameter a pointer to a location in memory that can hold a specified number of values? For example, if I have:

- (void)doSomethingWith:(int *)values;

I’d like to make it clear that the int * passed in should point to an allocated space in memory that’s able to hold 10 such values.

  • 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-06-05T19:23:16+00:00Added an answer on June 5, 2026 at 7:23 pm

    To directly answer your question, use an array argument with a bounds, e.g.:

    - (void)takeTenInts:(int[10])array
    

    Which specifies that the method takes an array of 10 integers.

    Only problem is the C family of languages do not do bounds checking, so the following is valid:

    int a[10], b[5];
    
    [self takeTenInts:a]; // ok
    [self takeTenInts:b]; // oops, also ok according to the compiler
    

    So while you are specifying the size, as you wish to do, that specification is not being enforced.

    If you wish to enforce the size you can use a struct:

    typedef struct
    {
       int items[10];
    } TenInts;
    
    - (void)takeTenInts(TenInts)wrappedArray
    

    Now this doesn’t actually enforce the size at all[*], but its as close a you can get with the C family (to which the word “enforcement” is anathema).

    If you just wish to know the size, either pass it as an additional argument or use NSArray.

    [*] It is not uncommon to see structures in C following the pattern:

    typedef struct
    {
       // some fields
       int data[0];
    } someStruct;
    

    Such structures are dynamically allocated based on their size (sizeof(someStruct)) plus enough additional space to store sufficient integers (e.g. n * sizeof(int)).

    In other words, specifying an array as the last field of a structure does not enforce in anyway that there is space for exactly that number of integers; there may be space for more, or fewer…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With Spring MVC, you can specify that a particular URL will handled by a
In code one can specify globally accessible constants/enums/etc once that can then be reused
Is it possible to specify that members of a nested class can be accessed
According to the C++ Primer book, the author mentioned that we can specify a
I am trying to specify in my RSpec tests that my controller should use
In phpunit we can specify the method was called with particular ->with($this->equalTo('foobar')) or any
I am creating a (recursive) method that will allow me to specify a root
There is a method getCompletionProposalAutoActivationCharacters in ContentAssistProcessor that can return characters which trigger the
On iOS there is this nice feature that an app developer can specify device-specific
I wanted to write an extension-method that would work on dictionaries whose values were

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.