Re: const functions

From: Alex Rousskov <rousskov@dont-contact.us>
Date: Mon, 22 Oct 2001 22:49:22 -0600 (MDT)

On Tue, 23 Oct 2001, Robert Collins wrote:

> I've been reading the gcc manual (shock, horror) and I ran across this
> function attribute:
>
> const
> Many functions do not examine any values except their arguments, and
> have no effects except the return value. 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 const. For example,
> int square (int) __attribute__ ((const));
>
> I've written a number of functions that meet these criteria in the
> auth code - is there any reason we can't use this?

I can think of a few reasons to avoid the hack.

        0. It has a double underscore
        1. It looks ugly
        2. It is highly unlikely to provide any measurable performance
           improvement for Squid in the foreseeable future
        3. The function that qualifies now may not qualify
           tomorrow, but the compiler will continue to
           over-optimize it, producing hard-to-find bugs
        4. We may think that a function qualifies, but it
           does not (same side-effects as in 3)
        5. Technically, it is compiler's work to find these functions
           automatically.

$0.02,

Alex.
Received on Mon Oct 22 2001 - 22:49:26 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:14:34 MST