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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:54:42+00:00 2026-05-26T05:54:42+00:00

I have a hash function defined in a header file which I want to

  • 0

I have a hash function defined in a header file which I want to make sure is being inlined, but it uses a very large const static buffer of ints. I am wondering whether this buffer will affect the ability of the function to be inlined. Here is the code,(it’s based on a crc32 implementation found here).

inline HashId hash(const void *value, const size_t length,
   const HashId previous = 0)
{
   // Here is the really large const static buffer.
   static const unsigned int crcTable[256] = { /* 256 Unique ints */ };

   // Short hash calculation
   unsigned char *cast = (unsigned char*) value;
   unsigned int crc32 = previous ^ 0xFFFFFFFF;
   for (size_t i = 0; i < length; ++i)
   {
      crc32 = (crc32 >> 8) ^ crcTable[ (crc32 ^ cast[i]) & 0xFF];
   }
   return (crc32 ^ 0xFFFFFFFF);
}

My hope is, that if the input is known at compile time, then this call will get compiled away into a single value. Is this expecting too much of the compiler? I’m compiling with gcc 4.6 with -O2, but I’m also interested to hear how other compilers might treat this.

  • 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-26T05:54:42+00:00Added an answer on May 26, 2026 at 5:54 am

    As Oli indicates, your best bet is to simply look at the compiler output. However, here are some things to consider:

    • If the contents of the static are truly constant you will be better putting this in an anonymous namespace. This ensures its initialization has nothing to do with calling the function.
    • type of the static. Your example is quite trivial and thus will probably be fine, but other types will be different. Note that the initialization of such statics may or must be
      deferred until the block is entered (puzzle through the standard at 6.7 if you want)
    • Multi-threading, relating to the previous this initialization may be required to use a mutex to prevent multiple threads from doing the initialization.

    Given the possible scenarios it’d be best to not have statics inside your function if you wish it to be inlined. But each compiler is different, and all types are not equal.

    Whether the compiler can actually reduce this function to a compile-time constant is just an extended issue to whether it can inline the static at all. You may also wish to look at constexpr specifier if you can use C++11.

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

Sidebar

Related Questions

I have to write my own hash function. If I wanted to just make
I have a struct defined in a header file with three other files that
According to MSDN , a hash function must have the following properties: If two
I have some questions about Perl's map function. Specifically: How does %hash = map
i have a long running function¹: public string FindPasswordFromHash(String hash) { ... } which
I have a hash in which I store the products a customer buys (
What I can think of is: Algo: Have a hash table which will store
So, I have a function pointer defined as: unsigned static int (*current_hash_function)(unsigned int); And
I have a class called GraphEdge which I would like to be uniquely defined
I have a hash map defined as class KeyType { int key; mutable bool

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.