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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:44:40+00:00 2026-06-08T22:44:40+00:00

I wonder if the two following implementations will produce exactly the same thing with

  • 0

I wonder if the two following implementations will produce exactly the same thing with the same performances whatever the compiler I use :

template<class T, unsigned int TSIZE> MyClass1
{
    static const unsigned int size_const = 0;
    public:
        inline void Loop()
        {
            for(unsigned int i = 0; i < TSIZE; ++i) {
                /* DO SOMETHING ON DATA */
            }
        }
        T _data[TSIZE];
};

template<class T, unsigned int TSIZE> MyClass2
{
    static const unsigned int size_const = TSIZE;
    public:
        inline void Loop()
        {
            for(unsigned int i = 0; i < size_const; ++i) {
                /* DO SOMETHING ON DATA */
            }
        }
        T _data[size_const];
};

In the first one, as TSIZE used in the loop is a template parameter, it is almost guaranteed that the compiler will unroll the loop if needed. If the loop is unrolled in the first case, would it be unrolled in the second case (the only difference is that TSIZE is stored in a static const) ?

Thank you very much.

  • 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-08T22:44:43+00:00Added an answer on June 8, 2026 at 10:44 pm

    Whether the compiler will perform the optimization or not is different from whether it will treat the value as a compile time constant. In your particular example, and because the static const has not been defined anywhere, if the linker did not complain it means that the compiler only used it as a const-expression (compile time constant). Also note that if the compiler was not considering size_const as a const-expression, then the line T _data[size_const] (I am assuming you lost the T on the copy) would not compile.

    Any odr-use (use other than as a compile time constant) of the static member would require a definition.

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

Sidebar

Related Questions

I just wonder whether there will be any conflict if two service intents are
Suppose we have following two classes: class Temp{ public: char a; char b; };
take two following classes: class Test1{ public: Test1()=default; Test1(char in1,char in2):char1(in1),char2(in2){} char char1; char
I wonder what scopes folowing two bindings have: bind(PermissionManager.class).in(Singleton.class); and bind(PermissionManager.class); I have read
I wonder if anyone knows why the following two pieces of code behave very
I wonder why diametrically opposed margins (a margin-top following a margin-bottom) between two block
I wonder what these two words mean. I encountered them in Doctrine's documentation ,
I wonder if there is a way of concating two strings in Silverlight inside
I wonder how to get a string (or array of strings) between two known
Having a two mongodb servers as master and slave, i wonder what is the

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.