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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:22:41+00:00 2026-05-11T00:22:41+00:00

I just joined a new C++ software project and I’m trying to understand the

  • 0

I just joined a new C++ software project and I’m trying to understand the design. The project makes frequent use of unnamed namespaces. For example, something like this may occur in a class definition file:

// newusertype.cc namespace {   const int SIZE_OF_ARRAY_X;   const int SIZE_OF_ARRAY_Y;   bool getState(userType*,otherUserType*); }  newusertype::newusertype(...) {... 

What are the design considerations that might cause one to use an unnamed namespace? What are the advantages and disadvantages?

  • 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. 2026-05-11T00:22:42+00:00Added an answer on May 11, 2026 at 12:22 am

    Unnamed namespaces are a utility to make an identifier translation unit local. They behave as if you would choose a unique name per translation unit for a namespace:

    namespace unique { /* empty */ } using namespace unique; namespace unique { /* namespace body. stuff in here */ } 

    The extra step using the empty body is important, so you can already refer within the namespace body to identifiers like ::name that are defined in that namespace, since the using directive already took place.

    This means you can have free functions called (for example) help that can exist in multiple translation units, and they won’t clash at link time. The effect is almost identical to using the static keyword used in C which you can put in in the declaration of identifiers. Unnamed namespaces are a superior alternative, being able to even make a type translation unit local.

    namespace { int a1; } static int a2; 

    Both a‘s are translation unit local and won’t clash at link time. But the difference is that the a1 in the anonymous namespace gets a unique name.

    Read the excellent article at comeau-computing Why is an unnamed namespace used instead of static? (Archive.org mirror).

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

Sidebar

Related Questions

Just joined a new project which they are using VC#2008 to build an application.
i just joined this new group and basically haven't even really done any heavy
once again it has happened... I joined a new project, composed of several plain
I just (re-)joined a company to work on some C++ projects. I'm looking at
I just joined a team thats developing a asp.net mvc 1 application. I only
Just what the title says, I need to change the password for an existing
Just looking for the first step basic solution here that keeps the honest people
just a quick question: I am a CS undergrad and have only had experience
Just bought a 2.4GHz Intel Core 2 Duo iMac with 2GB of memory and
Just getting my head around Ruby metaprogramming. The mixin/modules always manage to confuse me.

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.