logoalt Hacker News

account42today at 3:33 PM5 repliesview on HN

Unfortunate. There isn't ever a good reason to have an infinite loop so concerned compilers could have just diagnosed this as a warning.


Replies

echoangletoday at 3:39 PM

The article mentions a use case for that:

> What I found is that this is common in embedded and kernel code as a halt-on-error pattern. When a fatal error occurs and there’s no operating system to exit to, you simply stop:

show 2 replies
sumtechguytoday at 3:47 PM

> There isn't ever a good reason to have an infinite loop

That seems to be a very broad statement. For example in a system where interrupts mostly control things this sort of 'do not close the program' could be useful.

A guy I worked with had one I never would think of because I do not work in that field.

But yeah a warning would probably be useful.

not_the_fdatoday at 3:48 PM

Interrupt driven super loops are very common on bare metal systems.

mdspantoday at 3:51 PM

Compilers can still diagnose something as a warning even if it's not UB.

show 1 reply
weinzierltoday at 3:41 PM

For Rust the infinite loop is important enough to have its own keyword.

show 1 reply