Mail Archives: djgpp/2006/04/04/22:46:37
On 28 Mar 2006 02:47:27 -0800 in comp.os.msdos.djgpp, "Bob W"
<dontsend AT operamail DOT com> wrote:
>After suspecting that something around the clock()
>function is flawed in the new release of gcc 4.10,
>DJ's and Brian's posts to my previous thread have
>convinced me that the problem is not that simple.
>
>The following program was simplified as much as possible
>and it should be run with a command line parameter of
>11 or 12 (based on a 2GHz P4) to verify the effects:
>------------------
>
>#include <stdio.h>
>#include <stdlib.h>
>#include <time.h>
>
>int Ack(int m, int n) {
> return(m ? (Ack(m-1,n ? Ack(m,(n-1)) : 1)) : n+1);
>}
>
>int main(int ac, char **av) {
> int n = (ac == 2) ? atoi(av[1]) : 1;
> clock_t t0=clock();
> int ackret=Ack(3, n);
> clock_t t1=clock();
>
> printf("Ack(3,%d): %d\n", n, ackret);
> printf("Time: %g secs\n", 1.0*(t1-t0)/CLOCKS_PER_SEC);
> printf("t1:%d, t0:%d, cps:%d\n",t1,t0,CLOCKS_PER_SEC);
>
> return 0;
>}
>
>------------------
>
>Findings:
>- If compiled without optimisation the program is obviously slow,
> but it seems to work as it did with gcc 4.01.
>- Every optimisation level from -O to -O3 gives various problems,
> depending on the value of the command line parameter:
> - Wrong value returned by clock(). - OR -
> - Program terminates without message.
>
>Workaround:
>- Variable "ackret" must be declared static or made global.
>
>Conclusion:
> Maybe I should just wait for gcc 4.20 and use 4.01 in the
> meanwhile. In any case I would be grateful if someone could
> explain to me what is going on with gcc 4.10.
Didn't see anything similar reported against gcc 4; would be worth
reporting a bug, for the case with the command line causing an
incorrect reordering, to ensure that a fix gets worked on:
http://gcc.gnu.org/bugzilla/enter_bug.cgi
--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
Brian DOT Inglis AT CSi DOT com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
fake address use address above to reply
- Raw text -