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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:33:44+00:00 2026-05-21T02:33:44+00:00

The following quote is from C++ Templates by Addison Wesley . Could someone please

  • 0

The following quote is from C++ Templates by Addison Wesley. Could someone please help me understand in plain English/layman’s terms its gist?

Because string literals are objects with internal linkage (two string literals with the same value but in different modules are different objects), you can’t use them as template arguments either:

  • 1 1 Answer
  • 3 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-21T02:33:44+00:00Added an answer on May 21, 2026 at 2:33 am

    Your compiler ultimately operates on things called translation units, informally called source files. Within these translation units, you identify different entities: objects, functions, etc. The linkers job is to connect these units together, and part of that process is merging identities.

    Identifiers have linkage†: internal linkage means that the entity named in that translation unit is only visible to that translation unit, while external linkage means that the entity is visible to other units.

    When an entity is marked static, it is given internal linkage. So given these two translation units:

    // a.cpp
    static void foo() { /* in a */ } 
    
    // b.cpp
    static void foo() { /* in a */ } 
    

    Each of those foo‘s refer to an entity (a function in this case) that is only visible to their respective translation units; that is, each translation unit has its own foo.

    Here’s the catch, then: string literals are the same type as static const char[..]. That is:

    // str.cpp
    #include <iostream>
    
    // this code:
    
    void bar()
    {
        std::cout << "abc" << std::endl;
    }
    
    // is conceptually equivalent to:
    
    static const char[4] __literal0 = {'a', 'b', 'c', 0};
    
    void bar()
    {
        std::cout << __literal0 << std::endl;
    }
    

    And as you can see, the literal’s value is internal to that translation unit. So if you use "abc" in multiple translation units, for example, they all end up being different entities.‡

    Overall, that means this is conceptually meaningless:

    template <const char* String>
    struct baz {};
    
    typedef baz<"abc"> incoherent;
    

    Because "abc" is different for each translation unit. Each translation unit would be given a different class because each "abc" is a different entity, even though they provided the “same” argument.

    On the language level, this is imposed by saying that template non-type parameters can be pointers to entities with external linkage; that is, things that do refer to the same entity across translation units.

    So this is fine:

    // good.hpp
    extern const char* my_string;
    
    // good.cpp
    const char* my_string = "any string";
    
    // anything.cpp
    typedef baz<my_string> coherent; // okay; all instantiations use the same entity
    

    †Not all identifiers have linkage; some have none, such as function parameters.

    ‡ An optimizing compiler will store identical literals at the same address, to save space; but that’s a quality of implementation detail, not a guarantee.

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

Sidebar

Related Questions

I have the following query: SELECT * FROM quotes INNER JOIN quotes_panels ON quotes.wp_user_id
I have been trying to extract e-mail addresses from the following code for quite
I've borrowed the following code from Wei-Meng Lee's "Beginning Android Application Development": import android.content.Context;
Given following Statment: String query = "Select * from T_spareParts where SparePartPK IN (?
So I have the following value from database $atag = &lt;a href=&quot;http://blackberry.com/twitter&quot; rel=&quot;nofollow&quot;&gt;Twitter for
I just read this question and stumbled upon the following quote: Scala treats ==
I have the following text contained within a field in my DB: [quote:5a7b87febe=mr smith]This
I have the following lines in my ~/.emacs.d/init.el (custom-set-variables '(flymake-allowed-file-name-masks (quote ( (\\.cc\\' flymake-simple-make-init)
I am quite new to real use of templates, so I have the following
I have a few questions about the linkage from the following variables. By examples

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.