# is there a tool that will detect a recursive function call in C code? [closed]

I need to search and eliminate recursive function calls in an inherited code base. Thus far I was unable to find any tool that will do a static analysis and find these functions.

## 评论

### You might want to try cflow:

You might want to try cflow:

The cflow utility shall analyze a collection of object files or assembler, C-language, lex, or yacc source files, and attempt to build a graph, written to standard output, charting the external references.

It should print a callgraph and mark the recursive functions.

### If your code has indirect ca

If your code has indirect calls thru function pointers, detecting recursive calls in it could be extremely difficult (and probably impossible in the general case, since equivalent to the halting problem.).

But I am not sure at all that eliminating recursion is worth the effort. For some recursive algorithms or problems, you'll just replace it by simulating it with a stack (in heap), and that don't help much (and makes the code unreadable).

A more pragmatic solution (at least on Linux) would be to limit the stack size, and run tests till they break by filling the stack. Then you can use the debugger to understand how it happens.

I think you should not bother that much about recursion...

### CIL can produce a CFG for C

CIL can produce a CFG for C programs, but it is a bit like using a sledgehammer to put in a staple.