const weak variables are inlined.

Richard Guenther richard.guenther@gmail.com
Fri May 9 09:26:00 GMT 2008


On Thu, May 8, 2008 at 7:23 PM, 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?

Well, a weak definition doesn't really make sense to me - references
to that symbol will be always bound as there is a definition.  But maybe
I'm missing something...

At least the situation is different with -fPIC builds and

const int x = 5;

which we also use for optimization (likewise we will inline inline
declared functions but never non-inline declared functions).

> > >  So, I guess I'm inclined to add a note to the documentation for "weak"
> that
> > > says that the compiler is free to replace uses of non-volatile const
> weak
> > > variables as rvalues with their initializers.
> > >
> > >  Objections to that plan?
> > >
> >
> > See above.
> >
>
>  I don't understand what you're suggesting.  Originally, you agreed with
> option (2) -- leaving things as they are.  Are you now advocating option (1)
> -- issuing an error?

For weak definitions I advocate option (1) and for -fPIC (non-weak)
definitions I advocate option (2).

Richard.



More information about the Gcc-patches mailing list