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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:17:29+00:00 2026-05-15T19:17:29+00:00

How do #defines work in Objective-C? I have a background in C/C++ and am

  • 0

How do #defines work in Objective-C?

I have a background in C/C++ and am now trying to pick up Objective-C. #defines don’t seem to work in objective-c the same way they work in c and C++, where the compiler just replaces all references to the defines with what they are supposed to represent.

When I try to use #defines in Objective-C they only work sometimes. Like when I do something like this;

#define NUMBER 5

int myArray[NUMBER];

I get compiler errors saying there is a square bracket missing, where if I use this line instead it works fine;

int myArray[5];

Surely these should both be the same thing?

Also if I try to use #define value in any sort of equations I get similar sort of compiler errors. This code wont work;

#define NUMBER 5

float var = NUMBER * 0.2;

Where as this is fine;

float var = 5 * 0.2;

Anyone any idea why this might be, or how #defines are handled differently by the Objective-C compiler. I’m using XCode by the way, just incase that makes a difference.

  • 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-15T19:17:29+00:00Added an answer on May 15, 2026 at 7:17 pm

    #define in Objective-C works exactly the same way it works in C. All of your examples work fine for me in a quick test I tried. It’s likely you have some other problem which is making the errors you’re seeing – can you post your actual code and the text of your error messages?

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

Sidebar

Related Questions

I am using functions to work with database.. Now the way i have defined
I'm trying to understand Objective-C properties and I have some lingering questions about their
I'm having a hell of a time understanding pointers in Objective C. They don't
I'm new to Objective-C and iPhone development and have been using Apress' Beginning iPhone
I am just starting climbing the Objective C learning curve (using Nerd Ranch iOS
I'm a complete newbie to Objective-C, coming from a background of PHP, assorted dialects
The objective is to have a form reflect user's defined constraints on a search.
I have been knocking my head against the wall trying to figure whether it
Possible Duplicate: Objective-C Default Argument Value I couldn't find a way to define a
I have a service contract that defines a method with a parameter of type

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.