Direct recursion detection possible?

Ali Çehreli acehreli at yahoo.com
Thu May 25 15:51:15 UTC 2023


On 5/24/23 16:04, Cecil Ward wrote:

 > Is it possible for our compilers to detect direct infinite recursion ?

I agree the compiler can detect some cases. However, a diagnostic may 
not be what the programmer wants in all cases.

I am writing on this topic because I've recently been pleasantly 
surprised how dmd lets me inject assert(false) expressions during 
development:

void foo() {
   someCode();

   assert(false, "some information");

   moreCode();
}

I am a printf-style programmer, where I use such asserts as well.

I *think* the compiler used to complain about that in earlier versions 
(or maybe I remember compilers of earlier languages like C++?); the 
compiler would say "unreachable code".

I am thankful that dmd allows me do it during development and debugging.

So, your case may fall into this category where although it doesn't make 
sense, a programmer may have caused it intentionally.

Ali



More information about the Digitalmars-d mailing list