This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: const weak variables are inlined.


On May  8, 2008, Mark Mitchell <mark@codesourcery.com> wrote:

> Richard Guenther wrote:
>> explicitly declared weak inline functions cause an error since
>> and implicitly weak (-fPIC) inline functions are still inlined.

> OK.

>> Which would suggest we should also error for
>> 
>> const int x __attribute__((weak)) = 5;

> But, a const, weak, initialized variable makes more sense than a weak
> inline; the const-ness says that the value cannot be changed.  Why not
> allow users to express that?

Yup.  As long as we don't substitute uses of the variable for the
constant, we should be fine.  We shouldn't do this, because an
alternate definition might define it to something else.

There's a significant difference between this case and that of the
weak inline.  While both weak const variables and weak inline
functions may have their local definitions used in the end if no
stronger definitions are found, all of the const, the weak and the
initializer are meaningful in the case of the variable (const means
you can't modify the variable; weak means there might be another
stronger definition so don't count on this one being the ultimate
definition, and the initializer means this weak definition is to be
initialized like this), whereas for weak inline functions, the inline
is absolutely meaningless, for you can't possibly inline a weak
function without risk of using the wrong definition.

Whether weak inline should trigger an error, a warning or be silently
ignored is a different issue, but regarding weak inline and weak const
as the same kind of situation would be a mistake IMHO.

-- 
Alexandre Oliva         http://www.lsd.ic.unicamp.br/~oliva/
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}
FSFLA Board Member       ÂSÃ Libre! => http://www.fsfla.org/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]