Re: How to use __attribute__((used))?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Sep 17, 2013 at 7:54 AM, Paul Smith <paul@xxxxxxxxxxxxxxxxx> wrote:
> I'm confused about how to use __attribute__((used)).  I'm using GCC
> 4.8.1 on a GNU/Linux Intel system.
>
> I have various variables that I want to be kept even at high levels of
> optimization, so that when I'm debugging I can use them.  I noticed the
> "used" attribute, which the docs say:
>
>         This attribute, attached to a variable, means that the variable
>         must be emitted even if it appears that the variable is not
>         referenced.
>
> That sounds like just what I want.  But whenever I try to use this I get
> an error:
>
>    error: ‘used’ attribute ignored [-Werror=attributes]
>
> I don't know what this means.  I searched but basically just found some
> other questions without answers.

In your example code you are using the attribute on a local variable.
The used attribute is only meaningful on a function or global
variable.  It's intended to be used to force the function or global
variable to be emitted even if it is not used.

It sounds like you are looking for the ability to disable optimization
for a local variable.  It doesn't make sense to say that you want to
force a local variable to exist even at high levels of optimization.
At high levels of optimization local variables more or less disappear,
though debug info is able to track some cases.  In any case, GCC has
no such ability.

Ian





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux