Re: compiler warnings for unconditional recursive calls

Tech-Archive recommends: Fix windows errors by optimizing your registry




"cody" <deutronium@xxxxxx> wrote in message
news:%231RAZaVqHHA.4536@xxxxxxxxxxxxxxxxxxxxxxx
Why doesn't the compiler give me any warning if it encounters code like
the following:

void foo()
{
// some code here
// foo() ist not nested in a pre-condition loop, some if- or else-
// block and no return statement appears before it.
foo();
}

The compiler should recognize something like that, shouldn't it?


Why? The general case of determining whether code terminates is inhaously
hard (the "halting problem"), and the few specific cases a compiler might be
able to detect are such a timy minority it doesn't seem worth it. If you
really do need to be sure that a method terminates consider implementing a
loop variant of some sort (they're already in Spec#:
http://channel9.msdn.com/wiki/default.aspx/SpecSharp.LoopVariants). If you
really /really/ need to be sure that a method terminates, you probably
shouldn't be using C# but rather something formal like SPARK.
(http://www.praxis-his.com/sparkada/).


.



Relevant Pages

  • Re: fields for methods?
    ... but only by a compiler that is allowed to ... struct A {void foo();}; ... int static_instance i = 0; ... Is not possible because foo is the only member of A... ...
    (comp.programming)
  • Re: linking C++ functions in a C program
    ... contains one function named foo() which is compiled in C, ... Therefore, no matter how you classify bar(), this program ... void foo; ... guess the compiler can generate two references to foo, one adorned, ...
    (comp.lang.c)
  • Re: [C] return statement in void function?
    ... struct foo copy{ ... compiler really does have to think about. ... T foo (U fxn) ... > evaluates to void. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: linking C++ functions in a C program
    ... contains one function named foo() which is compiled in C, ... Therefore, no matter how you classify bar(), this program ... void foo; ... The C++ compiler processing main.C will see an extern "C" function named foo, and any time that C++ code calls it, it will call the unmangled C name instead of the default mangled C++ name. ...
    (comp.lang.c)
  • Re: Pointers to Functions
    ... >>inline void foo{ ... >>int main{ ... Yes it is using the latest VC++ optimising compiler, ... This is fine as the identifier foo is a const pointer to the function ...
    (alt.comp.lang.learn.c-cpp)