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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:48:53+00:00 2026-05-27T02:48:53+00:00

In our company, just until recently, we were not using namespaces because some compilers

  • 0

In our company, just until recently, we were not using namespaces because some compilers could not support them well.

This lead to numerous occurrences of the following mistake:

file_A.cpp

class Node {
    Data *ptr;
    Node() { ptr = new Data; }
    ~Node() { delete ptr; }
};

file_B.cpp

class Node {
    vector<int> v;
    Point *pt;
    Node(int x,int y) { pt = new Point(x,y); v.push_back(0); }
    ~Node() { delete pt; }
};

void foo() {
    Node n(10,10);
    ...
}    // calls file_B::~Node() !!!

Each author Node did not know the existence of the other Node, but since he expected that this class name might be reused, he refrained from creating a .hpp file with it.

The compiler silently removes one of the destructors, as their signature matches, and the bug is hard to find, since it may not replicate in different computers.

Once the error had been identified, people gradually became aware of it, and they try to seal the definitions in unnamed namespaces, or avoid inilining the member functions in the class’ body [see below].

  • Question 1: Since you can’t trust that the programmer will always remember to program defensively, is there a tool that can detect these “unintended weak link symbols” ?

    By unintended I mean, Node classes were not defined in .hpp files, and at least one class member doesn’t match between the class definitions…

  • Question 2: If we don’t use namespaces, but we do inline every function, is there a possibility that the auto-generated functions (copy-ctor, copy-assignment, destructor) will create the aforementioned “weak link bug” ?


Way 1: enclose in unnamed namespaces

namespace {
  class Node {
     Data *ptr;
     Node() { ptr = new Data; }
     ~Node() { delete ptr; }
  };
}

Way 2: avoid inlining

class Node {
   Data *ptr;
   Node();
   ~Node();
};

Node::Node()  { ptr = new Data; }
Node::~Node() { delete ptr; }
  • 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-27T02:48:54+00:00Added an answer on May 27, 2026 at 2:48 am

    If your code base is large enough to justify the effort, you could customize an existing compiler to tackle with your issue:

    1. The LLVM/Clang compiler is customizable (it is in C++, and I don’t know it very well).
    2. The GCC compiler (recent versions like 4.6) is extensible, either thru plugins coded in C, or thru extensions coded in MELT. MELT is a (free, GPLv3 licensed) high level domain specific language to extend GCC.

    In both cases, it is a effort of several days or weeks, and the most difficult is to understand partly the compiler internal representations (Gimple & Tree for GCC) and organizations (e.g. passes).

    I am the main author of MELT and I will be delighted to help you with MELT, so feel free to contact me.

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

Sidebar

Related Questions

Our company has recently switched version control systems to SVN using TortoiseSVN as our
An applet developed outside our company just started failing for some users this week.
We created an application profile using our company's Facebook account. Today, I've just finished
I have just upgraded our company's domain controller from NT 4.0 to Windows 2008
I just introduced SVN in our company for our Visual Studio projects and created
I'm developing an ASP .NET application, nothing fancy just another LOB App. Our company's
At my company, we develop our ASP.NET applications as websites and often just work
So we have recently started developing applications for the iPad for our company. Unfortunately
Recently a couple of WCF services have been introduced to our company's API. There
All applicants to our company must pass a simple quiz using C as part

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.