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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:18:20+00:00 2026-05-26T00:18:20+00:00

I’m currently working on a code project that requires me to replace certain strings

  • 0

I’m currently working on a code project that requires me to replace certain strings with hashes of those strings. Seeing as these strings will not change at runtime, it would be advantageous, efficiency wise, to have the c preprocessor run my hash function on each string that I declare to be hashed at compile time.

Is there any way to get the C preprocessor to run my hash function at compile time?

I know this doesn’t work the way I described above, but just to get an idea of where I’m going, here’s some pseudocode that uses a macro. Imagine that instead of simply expanding the macro, the preprocessor ran the hash function and expanded it to the return value of that hash function:

    #include <iostream>
    #include <string>

    #define U64_HASH(inputString) getU64HashCode(inputString)

    //my hash function
    unsigned long long getU64HashCode (string inputString)
    {
        /*code*/
    }

    int main()
    {
        cout << U64_HASH("thanks for helping me") << endl;
        return 0;
    }

Again, ideally the cout << U64_HASH("thanks for helping me") << endl; would expand to cout << 12223622566970860302 << endl;

I wrote a header file generator, and that works fine for this project.

Final Solution

I have decided to use John Purdy’s perl script for this project, as it is simply awesome,and allows me to feed the output I want directly to my compiler. Thanks very much, John.

  • 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-26T00:18:21+00:00Added an answer on May 26, 2026 at 12:18 am

    One way to accomplish this is to put all your strings into a header file, and name them:

    // StringHeader.h
    #define   helloWorld              "Hello World"
    #define   error_invalid_input     "Error: Invalid Input"
    #define   this_could_get_tedious  "this could get tedious"
    

    Then you can use those strings:

    #include "StringHeader.h"
    std::cout << this_could_get_tedious << std::endl;
    

    Then you can run a program on your StringHeader.h to hash each string, and generate a replacement header file:

    // Generated StringHeader.h
    #define   helloWorld              097148937421
    #define   error_invalid_input     014782672317
    #define   this_could_get_tedious  894792738384
    

    That looks very manual and tedious, at first, but there’s ways to automate it.

    For example, you could write something to parse your source code, looking for “quoted strings”. Then it could name each string, write it to a single StringHeader.h, and replace the inline quoted string with the new named string constant. As an additional step when you create the file, you could hash each string – or you could has the file in one go after you’ve created it. This could let you create a hashed and non-hashed version of the file (which could be nice to create a non-hashed Debug version, and a hashed Release version).

    If you do try that, your initial parser to look for strings will have to handle edge cases (comments, #include lines, duplicated strings, etc).

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

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.