title: GCC __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535)
body: <p>Pursuant to the post, <a href="https://stackoverflow.com/questions/11197992/standalone-functions-data-in-c">Standalone functions/data in C++</a>, I proceeded to put my "common data" in an anonymous namespace as below and everything worked great on Windows (Vista 64 bit) on VS 2005/2008/2010 </p>
  
  <pre><code>namespace {
    ...
    static std::string mystrings[] = {
       str1,
       str2,
       ...,
       strN
    };
    ...
  }
  
  namespace mynamesp {
     ...
     use mystrings[] here..
     ...
  }
  </code></pre>
  
  <p>But on Linux (so far tested RHEL5 built with GCC-4.1.2) I promptly got a segmentation fault.</p>
  
  <pre><code>$&gt;myprog 
  Segmentation fault
  $&gt;gdb myprog 
  GNU gdb Fedora (6.8-27.el5)
  Copyright (C) 2008 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
  and "show warranty" for details.
  This GDB was configured as "x86_64-redhat-linux-gnu"...
  (gdb) r
  Starting program: &lt;path/to&gt;/myprog 
  [Thread debugging using libthread_db enabled]
  [New Thread 0x2b8901a9da60 (LWP 32710)]
  
  Program received signal SIGSEGV, Segmentation fault.
  0x0000003e4ce9c928 in std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::basic_string ()
     from /usr/lib64/libstdc++.so.6
  (gdb) bt
  #0  0x0000003e4ce9c928 in std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::basic_string ()
     from /usr/lib64/libstdc++.so.6
  #1  0x00002b88ffde482b in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535)
      at &lt;path/to&gt;/mysource.cpp:140
  #2  0x00002b88ffde4d65 in global constructors keyed to _ZN91_GLOBAL__N__underscore_separated_path_to_mysource.cpp_00000000_6994A7DA2_1E () at &lt;path/to&gt;/mysource.cpp:12139
  #3  0x00002b890011a296 in __do_global_ctors_aux ()
     from &lt;path/to/libs&gt;/debug/libmylibd.so
  #4  0x00002b88ffcd7f33 in _init () from &lt;path/to/libs&gt;/debug/libmylibd.so
  #5  0x00002b8901672e40 in ?? ()
  #6  0x000000326940d22b in call_init () from /lib64/ld-linux-x86-64.so.2
  #7  0x000000326940d335 in _dl_init_internal () from /lib64/ld-linux-x86-64.so.2
  #8  0x0000003269400aaa in _dl_start_user () from /lib64/ld-linux-x86-64.so.2
  #9  0x0000000000000001 in ?? ()
  #10 0x0000000000000000 in ?? ()
  (gdb)
  </code></pre>
  
  <p>Line 140 in the backtrace call stack item #1 basically points to the end of my array of strings definition. I've seen some others get this error; but no obvious fixes. Appreciate any thoughts/ideas/corrections as always. Thanks!</p>