Mail Archives: djgpp/1997/05/10/03:03:04
In article <3373AC95 DOT 2D64 AT osu DOT edu>, Ross Litscher <Litscher DOT 1 AT osu DOT edu> posted:
>Hi, I am kind of new to c++ and brand new to djgpp. I got about 98% of
>the following code off the internet. The problem is that I get a warning
>after I compile this. It is as follows:
>
>vidmode2.cpp(30) Warning: implicit declaration of function 'int
>rand(...)'
You haven't include the header file delcaring 'rand'. Add
#include <stdlib.h> below the other #includes.
>
>The program still runs correctly and all, though. By the way, there is a
>point in the program where I wanted the drawing to screen to slow down a
>bit so I used a 'while' loop where a number increases by 1 until it
>reaches a certain number. Could someone look at this and tell me if
>there is a better way to do this? Or is this fine. Any other comments
[snip, code]
> int wait=0;
> while(wait < 5000) //just to slow down
> { //the writting to
> wait++; //video memory
> }
This is ugly, C already has a nice keyword for doing this:
for( int wait = 0; wait < 5000; wait++ )
{}
Second, the compiler might optimize this out to:
int wait = 5000;
or nothing at all, depending on which ANSI scoping it's
using and so you won't wait (I doubt that gcc is this clever
enough to do this, but with -O2/-O3, who knows ;-)
Third, this'll run at totally different speeds on different
computers.
The 'delay' function (#include <dos.h>) will delay for a
specified number of milliseconds, e.g.:
delay( 250 );
(A neater way to do this would be by:
#define WAIT_LENGTH 250
delay( WAIT_LENGTH );
or even better, calculating how long to wait based on how
fast the program is going at run time)
>Ross
>.
--
John Fremlin (dfremlin AT facstaff DOT wisc DOT edu)
(fremdh AT essex DOT ac DOT uk)
- Raw text -