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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:49:22+00:00 2026-06-15T22:49:22+00:00

I am trying to use block in macro definition but without a luck. Here

  • 0

I am trying to use block in macro definition but without a luck.

Here is the code:

#define IPHONE_OR_IPAD_BLOCK(void(^iphoneBlock)(void), void(^ipadBlock)(void)) ({ \
    if (iphoneBlock && (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)) \
    { \
        iphoneBlock(); \
    } \
    else if (ipadBlock) \
    { \
        ipadBlock(); \
    } \
})

and it doesn’t seem to compile.

How would you suggest using blocks in macro?

UPDATE: Thanks for quick reply to Ramy Al Zuhouri, I’ll stick with static function instead as it gives more type checking:

NS_INLINE void DoIphoneOrIpadBlock(void (^iphoneBlock)(void), void (^ipadBlock)(void))
{
    if (iphoneBlock && (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone))
    {
        iphoneBlock();
    }
    else if (ipadBlock)
    {
        ipadBlock();
    }
}
  • 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-15T22:49:23+00:00Added an answer on June 15, 2026 at 10:49 pm

    In a macro there isn’t any parameter check, change it this way:

    #define IPHONE_OR_IPAD_BLOCK(iphoneBlock, ipadBlock) ({ \
        if (iphoneBlock && (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)) \
        { \
            iphoneBlock(); \
        } \
        else if (ipadBlock) \
        { \
            ipadBlock(); \
        } \
    })
    

    If it gets used with wrong parameters you’d probably get a syntax error.
    If you don’t like this behaviour you could change it with an inline function.

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

Sidebar

Related Questions

I am trying to use this block of code to replace ALL 123's in
Trying to use code from here Im trying to incorporate both classes so that
I am trying to use OpenFileDialog as in the code below, but the compiler
I'm trying to use this code block of php in C#: $fb->api(array( 'method' =>
I'm trying to use a ManualResetEvent to block until a callback is executed, but
I'm trying to use shared_ptr for the first time here, but I'm having some
I'm trying to use jQuery.scrollTo plugin with accordion (where one block expands after clicking
I am trying to get a text block to resize vertically and use the
I am trying to use Objective-C blocks in an iPhone 3.1.3 app but am
I am trying to use the Enterprise Library 3.1 Validation Block for validating my

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.