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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:05:22+00:00 2026-06-12T20:05:22+00:00

I need a syntax that allows me to launch a block of code with

  • 0

I need a syntax that allows me to launch a block of code with a previous initialization of some variables, and after the block of code is executed I need to execute some code to deallocate some other variables.
So the code written inside the block should be executed in the middle of some other operations.

Here is what I got:

#define application(block) new Application(&argc, argv); auto __code= []() block ; __code(); mainApplication->launch()

The code that you see just initializes an application (a C++ object), so I use it this way:

application({
    < write the code >
});

This way I am sure that the application is always initialized, and launched after the block.
But I wonder if there is a way to keep away the round parenthesis, so that I can write it this way:

application{
    < write the code >
};

Also this way works but it should make the syntax lighter.

  • 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-12T20:05:23+00:00Added an answer on June 12, 2026 at 8:05 pm

    You can hide for-loops in a macro to achieve this.

    A call to this macro, followed by a block (or single statement), will insert the declaration decl with that block as its scope, and evaluate preexpr before and postexpr after the block:

    #define LET(decl, preexpr, postexpr) \
        for (int _loop = 1; _loop;) \
            for (decl; _loop && (preexpr, 1); postexpr, _loop = 0)
    

    This is C but should work in C++ too; of course, using macros is usually considered to be bad C++ style. The _loop variable and the loops should be optimized away by a good compiler.

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

Sidebar

Related Questions

I need syntax help with the following code logic: I have a code block
I need a case statement that allows partial matches. I get a syntax error,
What's the code syntax, and what all do I need to install and configure,
I need to print the source code of a project that consists of a
Possible Duplicate: Dynamic module import in Python I need a functionality that allows users
I need the right syntax for mysql trigger I'm using version 5.1 and the
I need help with LINQ syntax or methodology, not sure which. Here's my issue:
I need to do the following and I'm struggling with the syntax: I have
This is hopefully a softball syntax question: I need to call a method with
I'm somewhat new to SQL and need help with query syntax. My issue involves

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.