On 31/05/18 07:50, bintom wrote:
> I noticed that there are no library functions in Dev C++ to display
> a blinking message. So I wrote this function, which I hope does the job
> for any oneout there.
>
There are a number of "improvement opportunities" in this code. I don't
want to demoralise you by listing everything I can think of, especially
as that would also lead to discussions about details or alternative
constructions that are probably beyond what you are interested in at the
moment.
But there is a /big/ mistake here, IMHO - your delay loops. These are
bad for a number of reasons:
1. They are totally dependent on the individual computer for their
timing. Faster or slower processors will give you shorter or longer delays.
2. They are busy-waiting, blocking a cpu core while waiting.
3. The delays will vary according what else is going on in your machine.
4. If you change the optimisation level, or other compiler details, the
loops will change timings - the compiler is also free to see that the
loops are pointless and can be removed altogether.
So a "count for a bit" delay loop is almost never a good idea. (They do
see occasional use in embedded systems, for very specific purposes on
specific known chips for short delays. And even then, they are written
differently.)
Standard C++ libraries do not have a "wait a bit function". But every
multi-threaded or multi-processing OS has a "sleep" function of some
sort. If you are writing for a specific operating system, find out what
kind of "sleep" call it supports, and use it. If you are writing with a
cross-platform toolkit (like Qt, wxwidgets, etc.), then use the call
from those libraries.