Re: attribute pure and gcse

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

 



On Sat, Apr 03, 2004 at 09:20:40AM -0800, Dara Hazeghi wrote:
> 
> 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;
>         while(j!=a)
>         {
>                 k = j*k;
>                 j++;
>         }
>         return k;
> }
> 
> int main()
> {
>         return square(100) * square(100);
> }
k is 1
k is 2
k is 6
k is 24
k is 120
k is 720
k is 5040
k is 40320
k is 362880
k is 3628800
k is 39916800
k is 479001600
k is 1932053504

Perhaps "factorial" instead "square" would be a better name.
100! is a large number requiring special handling.

http://images.amazon.com/images/P/0698117530.01.LZZZZZZZ.gif

try :

static int square(const int a)
{
	return a * a;
}

-- 
Michael Mueller

[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