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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:26:04+00:00 2026-06-17T12:26:04+00:00

Besides the global scope, of course. I have a custom assertion class with a

  • 0

Besides the global scope, of course.


I have a custom assertion class with a macro to cache a reference to __FILE__:

#define DEFINE_THIS_FILE \
  static const char THIS_FILE__[] = __FILE__

For source code, using the macro is no big deal since each source has its own scope. However, templated classes can’t use source code, so I’m forced to do all my ASSERT() calls in the declaration/definition given by TemplateClass.h

If I use my macro outside of the class definition e.g. Singleton

DEFINE_THIS_FILE;

namespace NE
{
  template<typename T>
  class Singleton
  {
    ...
  }
}

Then the macro winds up in the same scope of any code that #includes Singleton, and the compiler throws a redefinition error for THIS_FILE__. (Of course, this only happens if the other code also uses the DEFINE_THIS_FILE macro.)

If I put the macro inside the declaration, the compiler won’t complain but the linker won’t be able to find THIS_FILE__ for any given instance of templated class e.g. Singleton:

namespace NE
{
  template<typename T>
  class Singleton
  {
    constexpr DEFINE_THIS_FILE;     // constexpr modifier required in this case
    ...
  }
}

I assume the linker error I get,
Undefined symbols for architecture x86_64:
"NE::Singleton<NE::NonTemplateType>::THIS_FILE__"

is caused by the template instances not existing in the same scope as where THIS_FILE__ was first defined, Singleton.h


OT: Is there a way to get all instances of my templated type Singleton to share a scope (global is unacceptable) so that all instances can use this static const macro?


Edit1
Further testing confirms: Using the macro DEFINE_THIS_FILE inside each templated method containing an ASSERT() will compile and run correctly….
In this case, the instances aren’t sharing a scope, but have a static const char THIS_FILE__ defined for each method. This works, but I suspect that it uses as much or more ROM than a std::assert (with its its implied allocation of __FILE__).

I’ll settle for this until an answer to OT comes about 🙂


Edit2
Silly me. Instead of using the workaround listed in edit above, I might as well create another macro, UNCACHED_ASSERT(argsToCheck) that directly uses __FILE__ instead of a const static representation.
Multiple ASSERTions per method could still benefit from the caching, though.

Still need an answer to OT, though.

  • 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-06-17T12:26:04+00:00Added an answer on June 17, 2026 at 12:26 pm

    You can place your declaration in unnamed namespace

    #define DEFINE_THIS_FILE namespace { static const char THIS_FILE__[] = __FILE__; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Besides the existence of Smarty.class.php (which is also arguable), how do we know that
I have some questions regarding a bootstrapper class. I am using ASP.NET MVC 3
I have global gems and various gemsets. I want to remove all gems of
I'm using custom cache on a page, leaving a timestamp to follow cached versions.
In MvvmLight, I found that beside Messenger.Default which is a kind of global static
Besides readability is there any significant benifit to using a CASE WHEN statement vs
Besides what it comes with in 2.0 (the generated aspnetdb.mdf), is there a standard
Besides <input type=button value=Click me />, <input type=submit value=Click me />, <a>Click me</a> ,
Besides a drag-and-drop UI designer are there any other missing features when developing for
...besides the fact that I am a total amateur? My table is set up

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.