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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:34:34+00:00 2026-05-23T12:34:34+00:00

If the TEST macro is not defined, I would like to know whether there

  • 0

If the TEST macro is not defined, I would like to know whether there is a performance difference in these two pieces of code:

void Func1(int a) {
   // ...
}

#ifdef TEST
Func1(123);
#endif

and:

void Func2(int a) {
#ifdef TEST
    // ...
#endif
}

Func2(123);

With TEST not defined, Func2 would become an empty function that the compiler should not call at all, isn’t it?

  • 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-23T12:34:35+00:00Added an answer on May 23, 2026 at 12:34 pm

    It pretty much comes down to whether that particular call to Func2 is inlined or not. If it is, then an optimizing compiler ought to be able to make an inlined call to an empty function the same as not calling it at all. If it isn’t inlined, then it’s called and returns immediately.

    As long as the function definition is available in the TU containing the call to Func2, there’s no obvious reason it won’t be inlined.

    This all relies on the fact that 123 is a literal, so evaluating the arguments of your call has no side-effects. The args have to be evaluated even if the function call has no effect, so:

    int i = 0;
    
    /* 'i' is incremented, even if the call is optimized out */
    Func2(++i);
    
    /* 'i' is not incremented when 'TEST' is undefined */
    #ifdef TEST
    Func1(++i);
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Test the following code: #include <stdio.h> #include <stdlib.h> main() { const char *yytext=0; const
After test driving Google Chrome for 30 minutes or so, I like it, even
Our Test DB is suddenly missing rows. We want them back. Is there a
The test form generated by ASMX is pretty handy for testing operations. However, there
I would like to replace the default malloc at link time to use a
I would like to see if you could orient me. It happens that I
I spent some time trying to write a 'helper' macro to test a parameter
I have a shoulda macro/method that tests controller responses for XPath conditions like so:
I have a smart pointer type, and would like to construct an object that
Is it possible to tell the C preprocessor to check whether a function (not

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.