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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:46:44+00:00 2026-05-28T03:46:44+00:00

Recently I have found and I have started using in my preprocessor the following

  • 0

Recently I have found and I have started using in my preprocessor the following code:

#define FOREACH(i,s) for(VAR(i,(s).begin()); i != (s).end(); i++)
#define VAR(a,b) __typeof(b) a=(b)

what makes my iterating easier. But unfortunately I don’t fully understand the second line, especially the __typeof keyword (and why those two underscores are used). I also assumed that the whole expression __typeof(b) is a type casting, but when I take it in parenthesis, why it does not work?

  • 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-28T03:46:44+00:00Added an answer on May 28, 2026 at 3:46 am

    Just assume some real values for i and s to see what it does:

    std::list<int> list;
    FOREACH(i, list)
    

    This will resolve in the macro FOREACH(i, list):

    for(VAR(i, (list).begin()); i != (list).end(); i++)
    

    Now resolve macro VAR(i, (list).begin()):

    __typeof((list).begin()) i = (list).begin();
    

    Where __typeof gets the type of the Argument (list).begin() which is in this case std::list<int>::iterator

    std::list<int>::iterator i = (list).begin();
    

    Now insert this into the for and get:

    for(std:list<int>::iterator i = (list).begin(); i != (list).end(); i++)
    

    As you see the __typeof part is no typecast but a declaration, so the paranthesis are wrong there.

    Also note the many comments on why not to use macros and __typeof in special!

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

Sidebar

Related Questions

I've recently started using flex4 and have found when I compile a file, the
I've been using extension methods quite a bit recently and have found a lot
I recently started programming in WinForms using C#. I have a requirement where I
I have recently started to learn using of Doctrine 2.0 framework for PHP. Now
I have recently started using CAML.NET IntelliSense for SharePoint with Visual Studio 2008; which
I'm a front end developer who's recently started using IntelliJ Idea for JS development.
I have recently started using Zend Framework. I started developing on my local XAMPP
I have recently found myself becoming more negative about EF and cannot help wondering
I have recently found out that there exists a method called nth_element in the
I am a windows dev, but I have recently found that I need to

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.