C++ Perpetuum Mobile
-
Wie kann ich in C++ ein Perpetuum Mobile Programm schreiben, das nie mehr aufhört zu laufen?
-
int main() { for (; ;) ; }
-
int main() { for(;1;); }
-
int main(){while(1){}}XD
-
int main(){ while(true) {} }
-
Kleine Anekdote zu Endlosprogrammen aus Herb Sutters GotW
Herb Sutter schrieb:
... and then the loop will stay stuck on that value until the machine on which the program is running runs out of power (due to local power outage or battery life limits), its operating system crashes (more common on some platforms than others), Sol turns out to be a variable star and scorches the inner planets, or the universe dies of heat death, whichever comes first.[1]
[1]Indeed, because the program keeps the computer running needlessly, it also needlessly increases the entropy of the universe, thereby hastening said heat death. In short, such a program is quite environmentally unfriendly and should be considered a threat to our species. Don't write code like this.[2]
[2] Of course, performing any kind of additional work, whether by humans or machines, also increases the entropy of the universe, thereby hastening heat death. This is a good argument to keep in mind for times when your employer requests extra overtime.