attribute pure and gcse

Dara Hazeghi
Sat Apr 3 17:20:00 GMT 2004

--- Eljay Love-Jensen <> wrote:

> What is "int square(int)" supposed to do?

Nothing actually :-) I just wanted an example of a
"pure" function which should in theory be CSEable
(from my understanding).

> If a is anything other than zero, a will be set to
> zero by the "a = 0 * a;" 
> (when j := 0).  And will remain zero for quite some
> time thereafter.

That's definitely true. My bad...

> Second, you may want to make square inline, so that
> it can be CSE'd.

Doesn't seem to help (added attribute

But my understanding is that a pure function should
have no "side-effects" thus two calls to it with the
same arguments should be able to be eliminated in
favor of a single call. This is what I need, and what
I thought the manual was implying. Perhaps I'm reading
it wrong though...?


P.S. Here's the (fixed) source in question:

static int square(int a) __attribute__ ((pure));

static int square(int a)
        int j=1, k=1;
                k = j*k;
        return k;

int main()
        return square(100) * square(100);

Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway

More information about the Gcc-help mailing list