0
votes

I'm trying to make a patch but i never met this type of warning:

warning: incorrect type in assignment (different modifiers)
expected struct ipt_entry *[assigned] e
got struct ipt_entry [pure] *

This error appears at this point:

e = ipt_next_entry(e);

While the declaration of both e and ipt_next_entry looks like this:

struct ipt_entry *e;

static inline __pure
struct ipt_entry *ipt_next_entry(const struct ipt_entry *entry)
{
       return (void *)entry + entry->next_offset;
}

My question exactly: What __pure does? What can i do? Where can I read something about this? I really can't find anything on the internet.

1
Found this quickly enough: lxr.free-electrons.com/source/include/linux/compiler-gcc.h#L94 it is a macro which expands to __attribute__((pure)), which you could have seen in the source code for yourself. So... ohse.de/uwe/articles/gcc-attributes.html#func-pure - Ed S.

1 Answers

2
votes

From http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html

pure

return value depends only on the parameters and/or global variables. Such a function can be subject to common subexpression elimination and loop optimization just as an arithmetic operator would be. These functions should be declared with the attribute pure. For example, int square (int) attribute ((pure)); says that the hypothetical function square is safe to call fewer times than the program says.

Some of common examples of pure functions are strlen or memcmp. Interesting non-pure functions are functions with infinite loops or those depending on volatile memory or other system resource, that may change between two consecutive calls (such as feof in a multithreading environment).

The attribute pure is not implemented in GCC versions earlier than 2.96.Many functions have no effects except the return value and their

Basically it is appended to functions which read global memory and do not modify anything. For eg, the strlen() function just reads the pointer and returns the length of the string, it doesn't modify the actual string.
On the other hand, strcpy() does modify the memory pointed to by one of the pointers.

Such attributes (pure, const etc) help the compiler to know some semantic meaning of a function call, so that it can apply higher optimization than to normal functions.

Read more from this lwn article: http://lwn.net/Articles/285332/