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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:34:27+00:00 2026-05-15T15:34:27+00:00

I was going over the C++ FAQ Lite online. I was browsing inlines again

  • 0

I was going over the C++ FAQ Lite online. I was browsing inlines again since I haven’t found a use for them and wanted to know how the stopped the circular dependency as showed in this answer. I first tried to do the, “Why inlines are better than defines.” example with the following code:

#define unsafe(i) \
    ( (i) >= 0 ? (i) : -(i) )

inline
int safe(int i)
{
    return i >= 0 ? i : -(i);
}

int f();

int main(void)
{
    int x(5);
    int ans;

    ans = unsafe(x++);
    cout << ans << endl;
    ans = unsafe(++x);
    cout << ans << endl;

    ans = safe(x++);
    cout << ans << endl;
    ans = safe(++x);
    cout << ans << endl;

    std::cin.get();
    return 0;
}

EDIT:

Great. Got the typo out of the way. Not that I’m bitter that I don’t find such errors or anything.

The output is now 6, 9, 9, 11.

However, even with pre-incrementation, shouldn’t the first value result in 7?

If the macro is being called twice, then doesn’t it go like this:

unsafe(x) // pre-incrementation doesn’t modify the value when called.

unsafe(++x) // for all intents and purposes, the incrementation happens before the second call, so the ++x. This is for the first ans = unsafe(x++) if it’s being called twice.

By the time we reach the second ans = unsafe(++x), shouldn’t the x have been incremented twice? Once by the double call and once when the first double call was finished?

  • 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-15T15:34:28+00:00Added an answer on May 15, 2026 at 3:34 pm

    Instead of:

    #define unsafe(i) \
        ( (i) >= 0 = (i) : -(i) )
    

    I think you want:

    #define unsafe(i) \
        ( (i) >= 0 ? (i) : -(i) )
    

    In response to your edit:

    After the first call to unsafe(x++), x is 7, even though the ans is 6. This is because you have the statement:

    ans = ( (x++) >= 0 ? (x++) : -(x++) )
    

    ans is assigned to the middle x++ after the left-most x++ is evaluated. As a result, ans == 6 but x == 7. The difference with unsafe(++x) is that ans is assigned to ++x, meaning the result is ans == x == 9.

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

Sidebar

Related Questions

I've moved to a new project team and while going over the codebase, found
I was going over AdventureWorks2008 database and wanted to create a new table that
Been going over my predecessor's code and see usage of the request scope frequently.
I've been going over and over this in my head, and I can't seem
I am going over/studying the facebook code that was leaked in 2007, I notice
So we start Scrum today and start going over story points estimates. The first
I'm going back over an old project where I added preprocessor functionality to Essence'
When I iterate over the values or keys are they going to correlate? Will
When creating an index over a column that is going to be UNIQUE (but
I sweated over the question above. The answer I'm going to supply took me

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.