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 7756791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:54:48+00:00 2026-06-01T12:54:48+00:00

Is it possible to use some thing like this in Objective-C: #define number_of_items 10

  • 0

Is it possible to use some thing like this in Objective-C:

#define number_of_items 10

and then using it as:

int arr[number_of_items];
  • 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-01T12:54:49+00:00Added an answer on June 1, 2026 at 12:54 pm

    Yes, assuming you mean Objective C. It’s pretty much a superset of “proper” C so this is perfectly okay. It’s also okay in both C and C++.

    You can see that it works in the following transcript:

    pax> cat qq.m
    #import <objc/Object.h>
    
    // First method.
    
    #define number_of_items 10
    int arr[number_of_items];
    
    // Second method.
    
    #define NUMBER_OF_ROWS 10
    @interface test : Object{ int xyzzy[NUMBER_OF_ROWS]; }
    @end;
    
    pax> vi qq.m ; gcc -o qq.o -c qq.m -lobjc
    
    pax> # no errors occurred
    

    And, now that we’ve finally seen what you’re actually using:

    #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    #define NUMBER_OF_ROWS_ (IS_IPAD? 18: 18)
    

    NUMBER_OF_ROWS_ is not a constant, since it depends on the return value of the function UI_USER_INTERFACE_IDIOM().

    In other words, it cannot be calculated at compile time. That’s why you’re getting the error. You can see this by compiling the following code:

    #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    #define NUMBER_OF_ROWS_ (IS_IPAD ? 18: 20)
    
    int UI_USER_INTERFACE_IDIOM(void) {return 20;}
    int UIUserInterfaceIdiomPad;
    
    int main (void) {
        int arr[NUMBER_OF_ROWS_];
        return 0;
    }
    

    Under gcc --pedantic, you get:

    qq.m: In function ‘main’:
    qq.m:8: warning: ISO C90 forbids variable length array ‘arr’
    

    You either need to use a dynamically adjustable collection like NSMutableArray or use an array of the maximum size desired and only use what you need of that.

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

Sidebar

Related Questions

I have some thing like this code: map<int, string> m; m[1] = a; m[2]
Is it possible to use something like this wrapper with fluent configuration? http://jeffreypalermo.com/blog/use-this-nhibernate-wrapper-to-keep-your-repository-classes-simple/ If
is it possible to use something like an vim-close/exit-Event to execute some last commands
If I will code some thing like following: typedef struct { int a; PTR1
I know it is possible to use jQuery to do something like: $('body').css('cursor','wait'); What
Is it possible to use [Range] annotation for dates? something like [Range(typeof(DateTime), DateTime.MinValue.ToString(), DateTime.Today.ToString())]
Is it possible to use COUNT in some way that will give me the
Is it possible to manage native libraries (.so) under maven? We use some jars
I'd like to use a C++ stack type in Objective-C, but I'm running into
I'm new to iOS and objective-C. Before I dive down into this I'd like

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.