delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/10/03:03:04

From: dfremlin AT facstaff DOT wisc DOT edu (John Fremlin)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: compile warning
Date: 10 May 1997 05:23:46 GMT
Organization: University of Wisconsin, Madison
Lines: 64
Message-ID: <5l10p2$541u@news.doit.wisc.edu>
References: <3373AC95 DOT 2D64 AT osu DOT edu>
NNTP-Posting-Host: f181-100.net.wisc.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019