False positive unused variable

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

 



Hi all,

  I have a use case where you get and post and item to a queue via it's
sequence number so code like this:

int64_t seq = seq_next (queue); /* get next free place */
struct item *item = queue_get (queue, seq); /* get the item at place 'seq'
*/

item->a = 1; /* we just fill in dummy data for the example */
item->b = 2;

queue_publish (queue, seq); /* publish place 'seq' as containing data */

Now the issue here is that since 'item' is never referenced by any
function, GCC, falsely sees item as being an unused variable. So far AFAIK
only a warning is issued and that can be ignored, but at one time in the
future I fear that the optimizer will kick in here and simply remove where
we fill item with data.

So does there exist a proper way to tell GCC that this is a false positive?
The only attribute I could find is (unused) which silences the warning but
ofc will only further tell GCC that the variable really is unused. Honestly
this feels like a need for there being a (used) attribute to inform the
compiler that yes this variable is indeed used even though it doesn't
detect it.

Regards,
  Henrik Holst



[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