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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:03:07+00:00 2026-05-18T21:03:07+00:00

My issue is based around Objective-C directives, and subtracting them. Below are my directives.

  • 0

My issue is based around Objective-C directives, and subtracting them. Below are my directives.

#define IS_IPAD FALSE
#define RECT_WIDTH IS_IPAD ? 725 : 280
#define RECT_PADDING IS_IPAD ? 50 : 10

If I NSLog("@%d", RECT_WIDTH - RECT_PADDING), then I get 50 and not 230. Why would this happen? The only way I can get it to work is to assign each to an int, then subtract those two.

  • 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-18T21:03:07+00:00Added an answer on May 18, 2026 at 9:03 pm

    This is because of the priority of operations. Your code expands to this:

    NSLog(@"%d", FALSE ? 725 : 280 - FALSE ? 50 : 10);
    

    Which, once “parenthesed” with respect to C’s operator precedence rules, gets you this:

    NSLog(@"%d", FALSE ? 725 : ((280 - FALSE) ? 50 : 10));
    

    This is a frequent problem with macros. They expand nearly as a copy-paste operation, so if you don’t take care, you may end up with operator priority problems (like you’re having now).

    You have two possibilities. Either add parentheses to your defines so this cannot happen:

    #define RECT_WIDTH (IS_IPAD ? 725 : 280)
    #define RECT_PADDING (IS_IPAD ? 50 : 10)
    

    Or, since this is determined at compile-time, you may use the #if directive:

    #if IS_IPAD == FALSE
     #define RECT_WIDTH 280
     #define RECT_PADDING 10
    #else
     #define RECT_WIDTH 725
     #define RECT_WIDTH 50
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've run into an animation issue (I think) with my TabBar based app. I
The issue is there is a database with around 20k customer records and I
Background: I'm building a view-based NSTableView-esque control in Cocoa/Objective-C that offers the ease of
I have a database issue that i currently cannot wrap my head around with
I've been toying around with Qt and ran into a small issue. I want
I'm just starting to teach myself Objective C and have been fooling around with
My question is based around invoking a server method by using the command pattern.
I have this idea I've been mulling around in my head based on another
My application allows rotating points around a center based on the mouse position. I'm
This issue came up when I got different records counts for what I thought

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.