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];
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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:
And, now that we’ve finally seen what you’re actually using:
NUMBER_OF_ROWS_is not a constant, since it depends on the return value of the functionUI_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:
Under
gcc --pedantic, you get:You either need to use a dynamically adjustable collection like
NSMutableArrayor use an array of the maximum size desired and only use what you need of that.