On Mon, Feb 22, 2010 at 04:00:34PM +0100, SF Markus Elfring wrote:
> Now I am interested if the software tool supports the check if the
> corresponding return value is used after the function call. How can it
> be detected by the semantic patch language if a result from a function
> with a non-void return type will be actually used.
I've never personally considered doing that using Coccinelle. What I
usually do is something similar to the following example:
--- snip ---
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
#include <stdlib.h>
#if defined(__GNUC__)
# if defined(__ICC)
# define ATTRIBUTE(x)
# else
# if ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
# define ATTRIBUTE(x) __attribute__(x)
# define CAN_USE_ATTRIBUTE 1
# else
# define ATTRIBUTE(x)
# endif
# endif
#else
# define ATTRIBUTE(x)
#endif
int f() ATTRIBUTE((warn_unused_result));
double g() ATTRIBUTE((warn_unused_result));
int main(int argc, char *argv[]) {
int f_v = f();
g();
return EXIT_SUCCESS;
}
int f() {
return 42;
}
double g() {
return 13.37;
}
--- snip ---
The attribute given to the two function definitions will make the compiler (GCC
in my case) emit a warning, if the return-value of the given function is unused
in the caller.
--
Alexander Færøy
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)