title: How to extract the source filename without path and suffix at compile time?
body: <p>Using both gcc with -std=c11 and g++ with -std=c++14.</p>
  
  <p>E.g. for a file named <code>src/dir/Hello.cxx</code> it should expand to something like e.g.:</p>
  
  <pre><code>const char basename[] = "Hello";
  </code></pre>
  
  <p>or</p>
  
  <pre><code>const char basename[] = getStaticBasename(__FILE__);
  </code></pre>
  
  <p>as where <code>getStaticBasename()</code> is a macro (for C sources) or constexpr function (for C++ sources) which results to "Hello".</p>
  
  <p>I have to avoid splitting the string from <code>__FILE__</code> at runtime, because the path and suffix must not be compiled into the executable in any way.</p>
  
  <p>The solution must be without dependencies to huge libraries such as boost.</p>
  
  <p>As I have no makefiles, solutions like <a href="https://stackoverflow.com/a/237635/2880699">this</a> cannot be used in my case.</p>
  
  <p>Did one have a solution for that?</p>
  
  <p>Edit 2015-07-02:</p>
  
  <ul>
  <li>I have no influence on how the compiler and linker was invoked (sometimes via makefile, sometimes from command line, or some IDE (Eclipse CDT managed make, Crossworks, Xcode et cetera. So the solution needs to be in code only.</li>
  <li>My use case is to provide some kind of "generic region identifier" for a small footprint logging solution. The application code (which uses my logger) should only <code>#include &lt;Joe/Logger.h&gt;</code> and within the later calls to e.g. <code>LOG_DEBUG(...)</code> I'll implicitely take use of the automatically generated "generic region identifier".</li>
  <li>My current solution is that the application code have to declare a <code>JOE_LOG_FILE_REGION(Hello);</code> (after <code>#include &lt;Joe/Logger.h&gt;</code>) before it could place <code>LOG_DEBUG(...)</code> in its code.</li>
  </ul>