title: How to specify priority in __attribute__((constructor)) for nested functions?
body: <p>As part of some utility macro I am writing, I am defining a nested function with <code>__attribute__((constructor))</code></p>
  
  <p>However, I need those constructors to happen before other constructor defined at global space.</p>
  
  <p>Unluckily though, when I specify a priority for the nested constructors they stop working altogether, and when I don't specify it they are the last to be invoked...</p>
  
  <p>Here is the proof:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  __attribute__((constructor(102))) void global_constructor_prio102(void) { printf("%s\n", __func__); }
  __attribute__((constructor())) void global_constructor(void) { printf("%s\n", __func__); }
  __attribute__((constructor(101))) void global_constructor_prio101(void) { printf("%s\n", __func__); }
  
  int main(int argc, char **argv)
  {
      printf("%s - gcc %s\n", __func__, __VERSION__);
  
      __attribute__((constructor(102))) void nested_constructor_prio102(void) { printf("%s\n", __func__); }
      __attribute__((constructor())) void nested_constructor(void) { printf("%s\n", __func__); }
      __attribute__((constructor(101))) void nested_constructor_prio101(void) { printf("%s\n", __func__); }
  
      return 0;
  }
  </code></pre>
  
  <p>And its output:</p>
  
  <pre><code>global_constructor_prio101
  global_constructor_prio102
  global_constructor
  nested_constructor
  main - gcc 8.1.0
  </code></pre>
  
  <p>Am I hitting a bug in GCC, or some obscure behaviour?
  Is there a way to make the nested constructor run before a global one?</p>
  
  <p>(repl link: <a href="https://repl.it/@agustinf_/Nested-constructors-fail-with-priority" rel="nofollow noreferrer">https://repl.it/@agustinf_/Nested-constructors-fail-with-priority</a>)</p>