attribute section in static locals

Paulo J. Matos paulo@matos-sorge.com
Wed Dec 7 18:17:00 GMT 2011


Hi,

The GCC manual says in 
http://gcc.gnu.org/onlinedocs/gcc-4.3.6/gcc/Variable-Attributes.html#index-g_t_0040code_007bsection_007d-variable-attribute-2216

"You may only use the section attribute with a fully initialized global 
definition because of the way linkers work. "

However, a static local seems to be ok. Should the documentation be updated?

Consider the case:
#include <stdio.h>

int foo(int);

int foo(int x)
{
   __attribute__((section("DBG_STRING")))
     static const char label[] = "MYTEXT";

   printf("%s", label);

   return x + 1;
}

which compiles without trouble.

Cheers,
-- 
PMatos



More information about the Gcc-help mailing list