S
Sohail Somani
Aren't busy loops bad for energy consumption?
Yep. I haven't done it for a while (8051 micro), but at the very least
you should use timers + interrupt functions.
Aren't busy loops bad for energy consumption?
Aren't busy loops bad for energy consumption?
Flash said:An infinite busy loop would be, but I don't think that is what Miguel
was suggesting. I've done an infinite loop of the form:
for (; {
suspend_processor();
do_something();
}
On another project:
for (; suspend_processor();
In each case, suspend_processor() stops the processor from executing
code until it receives an interrupt.
It's a kind of processor which simply continues execution from where
it left it when it receives an interrupt instead of jumping to an
interrupt handler defined in some interrupt table?
Juha Nieminen wrote, On 19/11/07 22:59:
It does the interrupt processing then returns and executes
do_something (in the first case). Also note that the second
example does *nothing* in the main loop apart from suspend
the processor.
The most common processor I've done this kind of loop on is the
Z80, but I've also used it on the TMS320C25 and maybe other processors.
Richard Heathfield said:(e-mail address removed) said:
Oops, good point.
Then I'd do it like this:
do
{
if(condition = yadayada())
{
moreyadayada();
}
} while(condition);
Simple logic, obvious control flow, no wild jumps, everything nicely
encapsulated in functions.
Richard Heathfield said:James Kuyper said:
(Hear hear.)
If you need to exit the loop "in the middle": while(1) { condition =
foo();
if(!condition) { break; } bar(); } it's always because of an exit
condition that may or may not be true, that you must test. (Were this not
so, you wouldn't be using a loop.) The obvious way to deal with such a
situation is:
while(foo())
{
bar();
}
for(yadayada(); condition; moreyadayada())
{
}
is clearer still, no?
Right.
CBFalconer said:How about:
do {
/* yada yada */
if (!exit_condition) {
/* more yada yada */
}
} while (!exit_condition);
fups set for c.l.c. Cross posting to c.l.c++ is unwise.
Richard Heathfield said:pete said:
That's not for C/C++, but for C-C++.
Keith Thompson said:[...]James said:Martin said:James Watt wrote:
can anyone tell me how to do an infinite loop in C/C++, please ?
There being no such language as C/C++, it is impossible to do anything
with it.
Actually, this came up in a job offer that explicitly listed, and I quote
...experience in C/C++ [is] an advantage, but not a requirement...
Are you saying there is no such thing?
Correct, there is no such language as "C/C++". C and C++ are two distinct
(but closely related) languages.
People often use the term "C/C++" as if it were the name of a language.
The charitable interpretation of this is that it really means "C and C++",
or "C or C++", or "C and/or C++".
Or perhaps "C || C++", which means that if C is good enough, you don't
need to go on to C++. }
Charlie said:C/C++ and C-C++ both invoke undefined behaviour.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.