Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Blinking message in Dev C++

95 views
Skip to first unread message

bintom

unread,
May 31, 2018, 1:50:59 AM5/31/18
to
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.

void Blink(char *str)
{ cout << "\n";

while(true)
{ cout << str;
for(long l1=0; l1<300000000; l1++);

for(int i=0; i<5; i++)
cout << "\b";
for(int i=0; i<5; i++)
cout << " ";

for(long l1=0; l1<300000000; l1++);

for(int i=0; i<5; i++)
cout << "\b";
}
}

int main()
{ Blink("Message"); }

Öö Tiib

unread,
May 31, 2018, 2:15:40 AM5/31/18
to
Seems waste of computing power. There is usually something more sane
than busy loop for delaying an action. That Dev C++ is AFAIK MinGW and
So you can use Windows functions like Sleep in it.

David Brown

unread,
May 31, 2018, 3:33:21 AM5/31/18
to
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.

Alf P. Steinbach

unread,
May 31, 2018, 3:53:25 AM5/31/18
to
On 31.05.2018 09:33, David Brown wrote:
> [snip]
> Standard C++ libraries do not have a "wait a bit function".

std::this_thread::sleep_for

Docs at

<url: http://en.cppreference.com/w/cpp/thread/sleep_for>

Example usage,

sleep_for( 2s );


Cheers!,

- Alf

David Brown

unread,
May 31, 2018, 4:12:24 AM5/31/18
to
Of course you are right.

Depending on the versions of his tools and libraries, he might not have
a C++11 threading implementation. But it should be the first thing to try.



Manfred

unread,
May 31, 2018, 9:53:52 AM5/31/18
to
Besides the loop counting problem, the above code doesn't display
anything on my terminal, due to the lack of any std::flush usage.
Moreover, the amount of '\b' outputs should match the message length.

More generally, text decoration is not really part of the language (and
I think it shouldn't); C++ inherits the very basic text rendering
features of C, which do not include things like blinking.
This sort of things falls more properly into the category of either
text-based or GUI-based text rendering.

If working with gcc (or other compiler that supports the \e escape
sequence) and an ECMA-48[*] compliant terminal (thanks to
https://stackoverflow.com/questions/26522542/nesting-text-decoration-using-vt100-escape-sequences)
the following will do (it is C code, but that's irrelevant here):

/* ----------------------------- */
#include <stdio.h>

int main()
{
puts("foo \e[05mbar\e[25m baz\e[m");
}
/* ----------------------------- */

Examples of terminals that will show the above properly include xterm
and putty, I didn't try any Windows native terminal.

Thanks to the OP, that re-awakened my curiosity about text-decorations
in terminal output.

[*]
https://www.ecma-international.org/publications/standards/Ecma-048.htm

bintom

unread,
May 31, 2018, 10:03:33 AM5/31/18
to
Thanks to the guidance from the group, I found the Sleep() function in windows.h that does what I need.

bintom

unread,
May 31, 2018, 10:04:53 AM5/31/18
to
Dev C++, which we use does not support sleep_for() but I found Sleep() from windows.h which does the job. Thanks.

David Brown

unread,
May 31, 2018, 10:13:36 AM5/31/18
to
Dev C++ is an IDE, not a compiler - it supports whatever compiler you
want, with whatever options you want, whatever libraries you want and
whatever standards you want (though it has a preference for gcc
compilers, I believe).

If you are using an older compiler, or not enabling C++11 (or newer)
standards, then you won't have sleep_for(). You might conceivably have
tools that support C++11 in general, but not all of the C++11 libraries.

Unless you have very good reasons not to (and programmer knowledge and
experience might be a good reason), I'd recommend using at least C++11
standard for new code - it is a significant step up in the language.

Jorgen Grahn

unread,
May 31, 2018, 10:43:34 AM5/31/18
to
On Thu, 2018-05-31, David Brown wrote:
...
> Unless you have very good reasons not to (and programmer knowledge and
> experience might be a good reason), I'd recommend using at least C++11
> standard for new code - it is a significant step up in the language.

I don't think not knowing all of C++11 is a reason to tell the
compiler to use C++98. I don't know all of C++98 either ...

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Öö Tiib

unread,
May 31, 2018, 11:34:38 AM5/31/18
to
On Thursday, 31 May 2018 17:13:36 UTC+3, David Brown wrote:
> On 31/05/18 16:04, bintom wrote:
> > On Thursday, May 31, 2018 at 1:23:25 PM UTC+5:30, Alf P. Steinbach
> > wrote:
> >> On 31.05.2018 09:33, David Brown wrote:
> >>> [snip] Standard C++ libraries do not have a "wait a bit
> >>> function".
> >>
> >> std::this_thread::sleep_for
> >>
> >> Docs at
> >>
> >> <url: http://en.cppreference.com/w/cpp/thread/sleep_for>
> >>
> >> Example usage,
> >>
> >> sleep_for( 2s );
> >>
> >>
> >> Cheers!,
> >>
> >> - Alf
> >
> > Dev C++, which we use does not support sleep_for() but I found
> > Sleep() from windows.h which does the job. Thanks.
> >
>
> Dev C++ is an IDE, not a compiler - it supports whatever compiler you
> want, with whatever options you want, whatever libraries you want and
> whatever standards you want (though it has a preference for gcc
> compilers, I believe).

That is ideal talk about normal IDE. ;) Just like it is tricky to
integrate something but Apple-approved-LLVM stuff into X-Code it is
tricky to integrate something but that outdated version of MinGW gcc
into that Dev C++.

>
> If you are using an older compiler, or not enabling C++11 (or newer)
> standards, then you won't have sleep_for(). You might conceivably have
> tools that support C++11 in general, but not all of the C++11 libraries.
>
> Unless you have very good reasons not to (and programmer knowledge and
> experience might be a good reason), I'd recommend using at least C++11
> standard for new code - it is a significant step up in the language.

There are number of other 0 price IDEs that are easier to deal with.
Eclipse CDT, NetBeans, Qt creator, even free vesions of MS VS are
relatively easy to to deal with. But one who has picked Dev C++ or
Code::Blocks should first just dump it if they want to use modern
compilers IMHO, YMMV.

woodb...@gmail.com

unread,
May 31, 2018, 2:12:09 PM5/31/18
to
On Thursday, May 31, 2018 at 9:43:34 AM UTC-5, Jorgen Grahn wrote:
> On Thu, 2018-05-31, David Brown wrote:
> ...
> > Unless you have very good reasons not to (and programmer knowledge and
> > experience might be a good reason), I'd recommend using at least C++11
> > standard for new code - it is a significant step up in the language.
>
> I don't think not knowing all of C++11 is a reason to tell the
> compiler to use C++98. I don't know all of C++98 either ...
>

Agreed. There's also an increasing amount of software
that you won't be to use if you don't take steps toward
2011 ++C. That includes code from an online code generator
that has been mentioned here previously.


Brian
Ebenezer Enterprises - Enjoying programming again.
https://github.com/Ebenezer-group/onwards

Scott Lurndal

unread,
May 31, 2018, 2:30:07 PM5/31/18
to
woodb...@gmail.com writes:
>On Thursday, May 31, 2018 at 9:43:34 AM UTC-5, Jorgen Grahn wrote:
>> On Thu, 2018-05-31, David Brown wrote:
>> ...
>> > Unless you have very good reasons not to (and programmer knowledge and
>> > experience might be a good reason), I'd recommend using at least C++11
>> > standard for new code - it is a significant step up in the language.
>>
>> I don't think not knowing all of C++11 is a reason to tell the
>> compiler to use C++98. I don't know all of C++98 either ...
>>
>
>Agreed. There's also an increasing amount of software
>that you won't be to use if you don't take steps toward
>2011 ++C.

Actually, that precludes the use of such software in many cases
where moving to a newer compiler isn't feasible.

On-line code generators aren't a viable solution - who wants to
be dependent upon a third-party that may disappear tomorrow?

David Brown

unread,
May 31, 2018, 2:53:20 PM5/31/18
to
I have only dealt with one on-line code generator (for making customised
SDK's for a family of microcontrollers), and I agree entirely. I'd
rather have a large download giving a big, fat tree of all the files for
all the devices in the family - so that I can pick the ones I want, when
I want, copy them, compare them, archive them.

woodb...@gmail.com

unread,
May 31, 2018, 9:07:46 PM5/31/18
to
I think those who will consider risking their futures with
Ebenezer will either be individuals or a small company.
Probably someone who knows that G-d has blessed them with
ideas/insights. Perhaps https://duckduckgo.com or maybe
an Israeli company. See http://webEbenezer.net/about.html
for more info.


Brian

bintom

unread,
Jun 1, 2018, 12:03:00 AM6/1/18
to
The syllabus of our school board (in India) still uses C strings and pre C++98 standards.

Next year, we will be moving to Python and things will get more standardized.

Paavo Helde

unread,
Jun 1, 2018, 1:43:18 AM6/1/18
to
On 1.06.2018 7:02, bintom wrote:
>
> The syllabus of our school board (in India) still uses C strings and pre C++98 standards.
>
> Next year, we will be moving to Python and things will get more standardized.

Python and standardized? You must be joking!


David Brown

unread,
Jun 1, 2018, 3:19:56 AM6/1/18
to
Don't mix religion and professional work (unless you work as a minister
or priest). No one cares what religious beliefs you or anyone else
might hold, or whether you see those beliefs as being the inspiration or
purpose behind your work - that is a personal thing. If your site is
worth using professionally, then it is worth using professionally
regardless of the user's beliefs.


David Brown

unread,
Jun 1, 2018, 4:40:38 AM6/1/18
to
Python has a different sort of standardisation from C++. There is no
ISO committee - but there is a strong Python Foundation. Within the
major versions (1.x, 2.x, 3.x) there is high backwards compatibility.

It is impossible to have a language (and standard libraries) where you
have strong standardisation so that any code can work with any system,
and at the same time you have a living language with continuous
improvement and new features. Python and C++ are both languages with
steady growth and change - C is a language with much stronger standards
but far slower rate of change.

And for teaching programming, Python is a better choice than C++ -
certainly a vastly better choice than an ancient version of C++.


woodb...@gmail.com

unread,
Jun 2, 2018, 1:46:25 PM6/2/18
to
I'm a bopper - Biblically oriented programmer. When I
say that I'd like to work with an Israeli company, they
are more likely to be boppers. You don't have to be a
bopper in order to get my help, but ideally I'd like to
work with other boppers.


Brian
https://github.com/Ebenezer-group/onwards

David Brown

unread,
Jun 2, 2018, 2:11:51 PM6/2/18
to
When you say things like that, the message you are giving is that your
are unable to separate your work from your private life, and you are
unable to work with people who /can/ separate them - i.e., the great
majority of people. You are chasing away everyone who is not a close
follower of your particular cult - including the vast majority of
Christians. If that's your choice, fine - but be aware of the consequences.


woodb...@gmail.com

unread,
Jun 2, 2018, 2:20:54 PM6/2/18
to
Not everyone is as bigoted as you are. They can
"taste and see" if they want to.

David Brown

unread,
Jun 2, 2018, 3:04:20 PM6/2/18
to
I don't care what religion people want to follow, or what nationality
they are - if I am dealing with a person or company professionally, I
only care about there work professionally. I only ask one thing - that
that person or company does not judge people on anything but /relevant/
issues.

You want to judge people based on their religion, their nationality,
their sexuality. You want to do so in your professional life. /That/
is bigotry.

(Note that this is different from ethics or human rights. It's fine to
say you don't want to work with companies that make bombs, or for your
software to be used to run a drug sales operation.)

If I have prejudices, it is only against bigots.


Anyway, enough of this - it is off-topic. You can accept the fact that
mixing religion with your professional work will limit your company's
potential sales and partners, or you can ignore it.

James Kuyper

unread,
Jun 2, 2018, 3:50:45 PM6/2/18
to
On 06/02/2018 02:20 PM, woodb...@gmail.com wrote:
> On Saturday, June 2, 2018 at 1:11:51 PM UTC-5, David Brown wrote:
>> On 02/06/18 19:46, woodb...@gmail.com wrote:
...
>>> I'm a bopper - Biblically oriented programmer. When I
>>> say that I'd like to work with an Israeli company, they
>>> are more likely to be boppers. You don't have to be a
>>> bopper in order to get my help, but ideally I'd like to
>>> work with other boppers.
>>>
>>
>> When you say things like that, the message you are giving is that your
>> are unable to separate your work from your private life, and you are
>> unable to work with people who /can/ separate them - i.e., the great
>> majority of people. You are chasing away everyone who is not a close
>> follower of your particular cult - including the vast majority of
>> Christians. If that's your choice, fine - but be aware of the consequences.
>
> Not everyone is as bigoted as you are. They can
> "taste and see" if they want to.

Being able to work with people who have different religious beliefs than
your own counts as a sign of bigotry? I don't see how that follows.

As far as I can see, "ideally I'd like to work with other boppers" is a
stronger indication of bigotry than anything David said. It's certainly
not a strong indication of bigotry - "I don't want to have anything to
do with anyone who isn't biblically oriented" would be a much stronger
indication. However, it's certainly not the statement of someone who's
lack of bigotry would allow him to deal with people of conflicting
religous beliefs as easily as with people who share his religious
beliefs, in any context where those religious beliefs are irrelevant.

woodb...@gmail.com

unread,
Jun 2, 2018, 3:57:54 PM6/2/18
to
On Saturday, June 2, 2018 at 2:04:20 PM UTC-5, David Brown wrote:
> On 02/06/18 20:20, woodb...@gmail.com wrote:
> >
> > Not everyone is as bigoted as you are. They can
> > "taste and see" if they want to.
> >
>
> I don't care what religion people want to follow, or what nationality
> they are - if I am dealing with a person or company professionally, I
> only care about there work professionally. I only ask one thing - that
> that person or company does not judge people on anything but /relevant/
> issues.
>
> You want to judge people based on their religion, their nationality,
> their sexuality.

You seem to have misunderstood me. When I say:
"You don't have to be a bopper in order to get my help,
but ideally I'd like to work with other boppers."

I'm saying that you can be whatever and I'll try
working with you. If I get more than one interested
party, I'll take their beliefs into account in terms
of my decision. Does G-d love atheists, Budhists,
Muslims, etc.? Yes, and so do I.

Like Ben Shapiro -
https://www.dailywire.com/podcasts/31337/ep-551-bee-or-not-bee

, I'm partial to western civilization.


Brian

Juha Nieminen

unread,
Jun 4, 2018, 3:01:15 AM6/4/18
to
bintom <binoyth...@gmail.com> wrote:
> for(long l1=0; l1<300000000; l1++);

Never, ever use a busyloop for anything.

You have zero control over how long it will actually take (it could very
well take exactly 0 seconds because the compiler could just see that the
loop isn't doing anything and optimize it away), and even when it's not
optimized away, you will be using the CPU core at 100% for doing
absolutely nothing.

Busyloops were common in 8-bit consoles and home computers, and extremely
early PC's (often because there was no alternative), but have been a bad
idea since forever.

Richard

unread,
Jun 4, 2018, 1:00:33 PM6/4/18
to
[Please do not mail me a copy of your followup]

bintom <binoyth...@gmail.com> spake the secret code
<6891548b-2313-444c...@googlegroups.com> thusly:

>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.

It doesn't work on my LA36.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
0 new messages