Re: __attribute__((warn_unused_result)

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

 





Mohanlal Jangir schrieb:
On 4/6/07, John (Eljay) Love-Jensen <eljay@xxxxxxxxx> wrote:
Hi Mohanlal,

That warning was introduced in GCC 3.4.

HTH,
--Eljay


Hi Eljay,

With same compiler, following program works well (compiles as well as
gives warning)
#include <stdio.h>

class myClass {
   public:
   int count() __attribute__((warn_unused_result));
};
[...]

The only problem is, the program does not work if I define the method
inside the class. Any clue ??

It is syntactically not possible to place attributes between the function head and the definition in gcc. The usual solution is to put it somewhere else. Have you tried:

class myClass {
   public:
   int __attribute__((warn_unused_result)) count()
   {
       return printf("hello world\n");
   }
};

The gcc manual is a bit misleading here, as it presents only examples where attributes are used in a function declaration and does not discuss how to use them in a definition-is-implicit-declaration situation.

I haven't tried the above with this particular attribute, but it works well with other function-relevant attributes such as always_inline.

Daniel

[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