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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:04:57+00:00 2026-05-24T13:04:57+00:00

As far as I am aware, the linker tries to merge two string literals

  • 0

As far as I am aware, the linker tries to merge two string literals into one single literal, if they are both the same, e.g.:

file1.c

char const* firstString = "foo";

file2.c

char const* secondString = "foo";

Would result in only one occurence of foo\0 in the respective memory section (saving 4 Bytes). This is especially important for embedded applications (how does avr-gcc vs. gcc behave).

But I was wondering if I can actually count on this to happen, and rely, that if two strings are equal, also their pointers are equal (provided that in the whole program, you only pass string literals around and no runtime generated strings exist — which is a reasonable assumption in my case). Obviously, I want to speed up speed comparisons with this, and allow a commonly used function to receive a string literal like so:

void lock(char const*);
void unlock(char const*);

lock("test");
dosmth();
unlock("test");

In essence, I want to avoid having a huge enum and huge switches inside the lock/unlock functions.

  • 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-24T13:04:58+00:00Added an answer on May 24, 2026 at 1:04 pm

    The linker doesn’t have to merge anything. It just has to map a declared type to a defined type. That involves finding the defined type and filling out the address offsets to jump to the right item.

    What you are talking about would be an optimizing linker. Many linkers don’t optimize at all, and those that do aren’t held to an optimizing standard, so you’ll never be able to generalize beyond the observed findings for the linker you discover (on that machine, at that time).

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

Sidebar

Related Questions

As far as I am aware C++ string declaration follows the form: std::string param;
As far as I'm aware there are two main styles of permissions systems out
Now before I dive too far into this this question, I am aware of
As far as I am aware there is no inbuilt polygon functionality for Python.
As far as tools go, I am aware of Haxe , MTASC , and
Far as best practices are concerned, which is better: public void SomeMethod(string str) {
So far I've found two different ways to access what I believe are equivalent
The advantages of DI, as far as I am aware, are: Reduced Dependencies More
I've answered two different questions now, both explaining how VOIP apps don't start on
As far as I am aware, IE9 should have CSS support for rounded corners.

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.