![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
I'm trying to comple this small program to waste CPU usage. The code is as follow:
Code:
#include <time.h>
#define SLEEPTIME 5
time_t start, end;
start=time(NULL);
end=start+SLEEPTIME;
while(end > start){
start=time(NULL);
}
Code:
g++ waste.cpp waste.cpp:6: error: ISO C++ forbids declaration of `start' with no type waste.cpp:6: error: conflicting types for `int start' waste.cpp:5: error: previous declaration as `time_t start' waste.cpp:7: error: ISO C++ forbids declaration of `end' with no type waste.cpp:7: error: conflicting types for `int end' waste.cpp:5: error: previous declaration as `time_t end' waste.cpp:9: error: syntax error before `while' Thank you much! |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
declare your variables.
|
|
#3
|
|||
|
|||
|
I think the compiler is confused - your code, as posted, looks reasonable. It looks like the compiler has already seen start referenced before. start is not a reserved word in C++. It also looks like variables are declared.
try something like this: Code:
#include <time.h>
#define SLEEPTIME 5
time_t start=time(NULL);
time_t end=start+SLEEPTIME;
while(end > start){
start=time(NULL);
}
|
|
#4
|
|||
|
|||
|
Quote:
try.cpp:8: error: syntax error before `while' could it be that SLEEPTIME is of int type and assigning to time_t variable is illegal? |
|
#5
|
|||
|
|||
|
As always, thank you so much Driver!
Yes, I am a newbie and still learning by way through trying out different applications. I just wanted a small program to waste cpu and yes portability a concern here. But i'll take up on your suggestion on trying it out with sleep() Cheers! |
|
#6
|
|||
|
|||
|
Ooooops. I assumed that was a snippet, not the whole thing...
All C, C++ code requires main() somewhere. That's the place where the program starts running. |
|
#7
|
|||
|
|||
|
Quote:
its been a while since ive played with c. and as stated before, you need the main() function. i thought it was just a "snippet" also. |
|||
| Google The UNIX and Linux Forums |