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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:57:28+00:00 2026-05-15T01:57:28+00:00

I am trying to learn and understand name mangling in C++. Here are some

  • 0

I am trying to learn and understand name mangling in C++. Here are some questions:

(1) From devx

When a global function is overloaded, the generated mangled name for each overloaded version is unique. Name mangling is also applied to variables. Thus, a local variable and a global variable with the same user-given name still get distinct mangled names.

Are there other examples that are using name mangling, besides overloading functions and same-name global and local variables ?

(2) From Wiki

The need arises where the language allows different entities to be named with the same identifier as long as they occupy a different namespace (where a namespace is typically defined by a module, class, or explicit namespace directive).

I don’t quite understand why name mangling is only applied to the cases when the identifiers belong to different namespaces, since overloading functions can be in the same namespace and same-name global and local variables can also be in the same space. How to understand this?

Do variables with same name but in different scopes also use name mangling?

(3) Does C have name mangling? If it does not, how can it deal with the case when some global and local variables have the same name? C does not have overloading functions, right?

Thanks and regards!

  • 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-15T01:57:29+00:00Added an answer on May 15, 2026 at 1:57 am

    C does not do name mangling, though it does pre-pend an underscore to function names, so the printf(3) is actually _printf in the libc object.

    In C++ the story is different. The history of it is that originally Stroustrup created “C with classes” or cfront, a compiler that would translate early C++ to C. Then rest of the tools – C compiler and linker would we used to produce object code. This implied that C++ names had to be translated to C names somehow. This is exactly what name mangling does. It provides a unique name for each class member and global/namespace function and variable, so namespace and class names (for resolution) and argument types (for overloading) are somehow included in the final linker names.

    This is very easy to see with tools like nm(1) – compile your C++ source and look at the generated symbols. The following is on OSX with GCC:

    namespace zoom
    {
        void boom( const std::string& s )
        {
            throw std::runtime_error( s );
        }
    }
    
    ~$ nm a.out | grep boom
    0000000100001873 T __ZN4zoom4boomERKSs
    

    In both C and C++ local (automatic) variables produce no symbols, but live in registers or on stack.

    Edit:

    Local variables do not have names in resulting object file for mere reason that linker does not need to know about them. So no name, no mangling. Everything else (that linker has to look at) is name-mangled in C++.

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

Sidebar

Related Questions

I am a ASP.NET Developer trying to learn Rails and RESTful approach. To understand,
im just starting to learn flex and im trying to understand how Flex does
I am trying to learn some of the basic and advanced features of visual
i'm trying to learn codeigniter (following a book) but don't understand why the web
Im trying to learn how to set up a Zend framework web application from
I'm trying to learn Scheme from the book The Little Schemer using DrScheme on
I am trying to learn jQuery and I posted a question asking for some
I am trying to learn how to import from XML to JTable. I am
I'm currently trying to learn Ruby and I'm trying to understand more about what
Trying to learn a bit of CSS and I want a horizontal navbar and

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.