Package: gcc

Version: 4:4.6.3-8

 

Using Debian Wheezy with Raspberry Pi.

 

The 'newline' characters (\n) seem to have an effect on compilation.

 

I have used three test programs:

 

test1.c

 

#include <stdio.h>

#include <time.h>

 

float      delay(float time_delay)

{

float      time1,time2;

time1 = clock()/CLOCKS_PER_SEC;

time2 = clock()/CLOCKS_PER_SEC;

while (time1 < time2 + time_delay)

            {

            time1 = clock()/CLOCKS_PER_SEC;

            }

return time1;

}

 

main()

{

int        i;

float      print_time;

float      delay_time = 2.0;

for (i=1;i<=3;i++)

            {

            printf("Loop number %d",i);

            printf("*")

            print_time = delay(delay_time);

            printf("    *  Time = %1.3f",print_time);

            }

}

 

What I think should happen:

1.         print "Loop number 1"

2.         print "*"

3.         wait 2 seconds

4.         print "    * Time = 2.000"

5.         print "Loop number 2"

6.         print "*"

7.         wait 2 seconds

8.         print "    * Time = 4.000

Etc

What actually happens:

1.         delay 6 seconds

2.         print "Loop number1*     * Time = 2.000Loop number2*    * Time =
4.000Loop number3*    * Time = 6.000"

 

test2.c is exactly the same as test1.c with one exception: the last printf()
has a new line character.

 

What I think should happen:

1.         print "Loop number 1"

2.         print "*"

3.         wait 2 seconds

4.         print "   * Time = 2.000"

5.         newline

6.         print "Loop number 2"

7.         print "*"

8.         wait 2 secons

9.         print "    * Time = 4.000"

10.       newline

Etc

 

What actually happens:

1.         wait 2 seconds

2.         print "Loop number1*    * Time = 2.000"

3.         newline

4.         wait 2 seconds

Etc

 

test3.c is exactly the same as test2.c with one exception: the printf("*")
is replaced by printf("*\n")

 

The program now runs as expected.

------------------------------------------------------------------

Wendy and Dennis Butler

+61 (0)3 63 272425  (Home)

+61 (0)427 242524  (Wendy mobile)

+61 (0)448 272425  (Dennis mobile)

 

Reply via email to