0

I'm trying to measure the time it takes my program to perform multiple operations in a loop and the entire program is written in C. I'm using the method from this post:

C# vs C - Big performance difference

However, when I try doing that method, on the declaration line for clock(), I get an error: Improper use of typedef symbol in function main.

The header file is included and does not cause any errors. This is a 16-bit C program written in the TurboC compiler for MS-DOS. I'm not sure which version of C it's using, but I think it's most likely C89 or one of the earlier versions of C. I don't know if that causes any syntax differences or not?

Here's the code I'm using:

clock_t start = clock();
while(count < 10000)
{
     count++;
}
printf("Time elapsed: %f\n", ((double)clock() - start) / CLOCKS_PER_SEC);   

And the error is exactly as I mentioned above.

Community
  • 1
  • 1
Generalkidd
  • 579
  • 1
  • 8
  • 22
  • Please post your code – Chris Laplante Nov 04 '13 at 17:58
  • Post the actual error message and/or try using a compiler from, say, the last 10 years rather than the ancient, crusty and non-standard Turbo C. – Paul R Nov 04 '13 at 17:59
  • This specific program needs to be written for 16-bit MS-DOS computers and thus, I have to use a compiler that's supported by MS-DOS. As far as I know, TurboC was the best unless there's a better, more standard compiler for MS-DOS? – Generalkidd Nov 04 '13 at 18:11

1 Answers1

2

In old-timey 16-bit C, you probably should use time_t and the time() function. They've been used for this purpose since approximately when email was invented.

Your code will die a horrible death sometime in 2038 if you do this. http://en.wikipedia.org/wiki/Year_2038_problem

 #include <time.h>
 time_t start = time();
 /* do a bunch of stuff */
 time_t stop = time();
 unsigned long int elapsedSeconds = stop - start;

If something goes wrong with using time_t declarations, try unsigned long int instead.

O. Jones
  • 103,626
  • 17
  • 118
  • 172
  • I've tried it with time_t but I still get the same typedef error. If I switch them to other variable types like unsigned long int, I get a new error: "Expression syntax in function main". In fact, I noticed that if I even try to comment the code out using // I still get the same expression syntax error. – Generalkidd Nov 04 '13 at 18:10