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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:08:09+00:00 2026-06-10T01:08:09+00:00

The following code compiles: ^{}(); And this compiles: void (^x)(); (x = ^{})(); But

  • 0

The following code compiles:

^{}();

And this compiles:

void (^x)();
(x = ^{})();

But this doesn’t:

(void (^x)() = ^{})();

The error I get is Expected ')'. Is this a bug with llvm or something? It’s totally holding me back from pretending Objective-C is JavaScript.

  • 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-10T01:08:11+00:00Added an answer on June 10, 2026 at 1:08 am

    This wouldn’t make sense in a C-like language. To see why, let’s build the statement from the ground up.

    First, we’ll use your working declaration for x:

    void (^x)();
    

    Now let’s initialize it in the same statement:

    void (^x)() = ^{};
    

    So far so good – x has been initialized with the correct block. So let’s invoke x now. But where will the () go? Naturally, we need to place the () immediately after a block-valued expression. However, in C, declarations are statements, not expressions so

    (void (^x)() = ^{})();
    

    doesn’t make sense. The only place the () can go is after the ^{}:

    void (^x)() = ^{}();
    

    But ^{}() has type void, not type void (^)().

    To sum up: you can’t declare a block variable and invoke it at the same time. you’ll have to either declare and initialize the variable, and then call it

    void (^x)() = ^{};
    x();
    

    or declare it and then assign and call it

    void (^x)();
    (x = ^{})();
    

    or just separate all three:

    void (^x)();
    x = ^{};
    x();
    

    As a concluding thought, let’s say it was desirable to declare and invoke blocks at the same time. If we decided to allow code like (void (^x)() = ^{})();, then for the sake of consistency, we would have to also allow code such as ++(void x = 4); or (void x = 1) + (void y = 2);. I hope you’ll agree that these just look strange in C.

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

Sidebar

Related Questions

The following code when compiled give this error I cannot understand why this is
The following code compiles in Visual C++ and gcc, but fails with Code Warrior
the following code compiles with Visual Studio 2008 but not with g++ on Mac
Running the following C# code through NUnit yields Test.ControllerTest.TestSanity: Expected: `<System.DivideByZeroException>` But was: null
In the following code, I get an error when I typecast the float pointer
I wanted to use boost::thread in my program, but get the following compiler error
The following code doesn't compile with gcc, but does with Visual Studio: template <typename
In C++ the following code gives a compiler error: void destruct1 (int * item)
The following code gives a compiler error in C++: const double** x; const void**
The following source code compiles correctly with Visual Studio 2010: namespace NS { class

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.