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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:59:28+00:00 2026-06-14T01:59:28+00:00

When declaring a block what’s the rationale behind using this syntax (i.e. surrounding brackets

  • 0

When declaring a block what’s the rationale behind using this syntax (i.e. surrounding brackets and caret on the left)?

(^myBlock) 

For example:

int (^myBlock)(int) = ^(int num) {
    return num * multiplier;
};
  • 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-14T01:59:30+00:00Added an answer on June 14, 2026 at 1:59 am

    C BLOCKS: Syntax and Usage

    Variables pointing to blocks take on the exact same syntax as variables pointing to functions, except * is substituted for ^. For example, this is a function pointer to a function taking an int and returning a float:

    float (*myfuncptr)(int);
    

    and this is a block pointer to a block taking an int and returning a float:

    float (^myblockptr)(int);
    

    As with function pointers, you’ll likely want to typedef those types, as it can get relatively hairy otherwise. For example, a pointer to a block returning a block taking a block would be something like void (^(^myblockptr)(void (^)()))();, which is nigh impossible to read. A simple typedef later, and it’s much simpler:

    typedef void (^Block)();
    Block (^myblockptr)(Block);
    

    Declaring blocks themselves is where we get into the unknown, as it doesn’t really look like C, although they resemble function declarations. Let’s start with the basics:

    myvar1 = ^ returntype (type arg1, type arg2, and so on) {
        block contents;
        like in a function;
        return returnvalue;
    };
    

    This defines a block literal (from after = to and including }), explicitly mentions its return type, an argument list, the block body, a return statement, and assigns this literal to the variable myvar1.

    A literal is a value that can be built at compile-time. An integer literal (The 3 in int a = 3;) and a string literal (The “foobar” in const char *b = “foobar”;) are other examples of literals. The fact that a block declaration is a literal is important later when we get into memory management.

    Finding a return statement in a block like this is vexing to some. Does it return from the enclosing function, you may ask? No, it returns a value that can be used by the caller of the block. See ‘Calling blocks’. Note: If the block has multiple return statements, they must return the same type.

    Finally, some parts of a block declaration are optional. These are:

    • The argument list. If the block takes no arguments, the argument list can be skipped entirely.

    Examples:

    myblock1 = ^ int (void) { return 3; }; // may be written as:
    myblock2 = ^ int { return 3; }
    
    • The return type. If the block has no return statement, void is assumed. If the block has a return statement, the return type is inferred from it. This means you can almost always just skip the return type from the declaration, except in cases where it might be ambiguous.

    Examples:

    myblock3 = ^ void { printf("Hello.\n"); }; // may be written as:
    myblock4 = ^ { printf("Hello.\n"); };
    
    // Both succeed ONLY if myblock5 and myblock6 are of type int(^)(void)
    myblock5 = ^ int { return 3; }; // can be written as:
    myblock6 = ^ { return 3; };
    

    source: http://thirdcog.eu/pwcblocks/

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

Sidebar

Related Questions

The syntax for declaring a property referring to a block is: typedef void (^voidBlock)();
I'm declaring a block like this: void (^callback)(NSString *_accessToken) = ^{ // do something
I'm trying to make a good block-based initializer for an objective-c class. I'm declaring
When declaring any primitive type data like int or double they get initialized to
When declaring external ant tasks using taskdef, for instance ant-contrib, the proposed setup is
I'm having trouble declaring a const field in an abstract class. Why is this?
Block syntax in Objective C (and indeed C, I presume) is notoriously incongruous. Passing
Is it possible to make this code a little more compact by somehow declaring
If I am using a try/catch/finally block where and how should I initialize variables?
This is a question of what the 'best practice' is for declaring new variables,

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.