Remix.run Logo
inkysigma 4 hours ago

One example along this path as an example is that every function must either terminate or have a side effect. I don't think one has bitten me yet but I could completely see how you accidentally write some kind of infinite loop or recursion and the function gets deleted. Also, bonus points for tail recursion so this bug might only show up with a higher optimization level if during debug nothing hit the infinite loop.

account42 2 hours ago | parent | next [-]

Infinite loop without side effects == program stuck and not responding on user input and not outputting anything. That's not something a useful program will ever want to do.

Certhas an hour ago | parent | next [-]

Not true, C++ made it so trivial infinite loops are not UB because it turns out they do have legitimate uses.

https://lists.isocpp.org/std-proposals/2020/05/1322.php

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p28...

account42 an hour ago | parent [-]

Yes, the C++ committee has been making some stupid decisions lately. This is not the only one.

Low level platform-specific code that needs to hot spin until an interrupt happens can use assembly for that part which it will need to do for the interrupt handler anyway.

zarzavat an hour ago | parent | prev | next [-]

https://9p.io/sources/plan9/sys/src/libc/9sys/abort.c

account42 an hour ago | parent [-]

This is already UB without an infinite loop.

xigoi 2 hours ago | parent | prev [-]

The problem is when you accidentally write an infinite loop. In a different language, you run the code, see that it gets stuck and fix it. In C, the compiler may delete the function, making it hard to realize what is happening.

account42 an hour ago | parent | next [-]

This is not a problem that C or C++ programmers actually encounter, ever.

1718627440 an hour ago | parent | prev [-]

Note, that this is not true for C.

1718627440 an hour ago | parent | prev [-]

That's only true in C++ though, not in C.

dzaima 38 minutes ago | parent [-]

C does allow unconditional infinite loops (e.g. "while (1) { }" isn't UB) but still is UB if the controlling expression isn't constant (e.g. "while (two < 10) { }" is UB if two is less than 10)