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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:42:16+00:00 2026-05-29T11:42:16+00:00

Simple question: When the compiler faces a call to, say, pow() with two constants

  • 0

Simple question: When the compiler faces a call to, say, pow() with two constants (i.e. values from macros), is it optimized by evaluating it at compile time, or is it still calculated at run-time?

Example:

#define V_BITMEM_GRID 3
#define V_BITMEM_TOTAL pow(V_BITMEM_GRID,2)

Thanks!

EDIT If not, is there a way to calculate the square/cube of a macro as another macro (like I’m attempting above) at compile-time?

  • 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-29T11:42:17+00:00Added an answer on May 29, 2026 at 11:42 am

    It can be both. It depends on how intrusive the compiler is, whether it has access to the function implementation and can correctly evaluate it. There’s no rule that specifies how it’s supposed to be, as long as observed behavior is the same.

    For example, I got the following:

    #define X 1
    #define Y 2
    int foo(int x, int y)
    {
        return x + y;
    }
    
    int main(int argc, char* argv[])
    {
        cout << foo(X,Y);
    00BE1000  mov         ecx,dword ptr [__imp_std::cout (0BE203Ch)] 
    00BE1006  push        3    
    00BE1008  call        dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0BE2038h)] 
    }
    

    The function, as you can see, isn’t even called. So it is possible that the call is eliminated for good.

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

Sidebar

Related Questions

my question today is pretty simple: why can't the compiler infer template parameters from
Here is one very simple question(or at least at first sight).Let's say we have
Simple question - why does the Decimal type define these constants? Why bother? I'm
This is a simple question. If the content of two lambda expressions in the
This seems like it should be a simple question. I have two QSpinBoxes in
Probably a simple question: Why do I get an compiler warning for the following
My question is pretty simple: Does the compiler treat all the methods in a
This should be very simple question. There are many programming languages out there, compiled
Simple question, but one that I've been curious about...is there a functional difference between
Simple question, how do you list the primary key of a table with T-SQL?

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.