Counting functions in C source code

后端 未结 6 921
隐瞒了意图╮
隐瞒了意图╮ 2021-01-19 08:17

I have complete project in C, which can be built with gcc or Visual Studio. There are no calls to external libraries.

I would like to know how many functions there

6条回答
  •  醉梦人生
    2021-01-19 08:36

    The definition of functions might be not as simple as you believe. In particular, functions in the C source code do not match functions in the generated assembly code, notably because of inlined functions.

    The number and size of functions depend upon the optimization level and the compiler.

    And many headers (e.g. ) could contain inline functions. If they are not called, the compiler probably would optimize by not emitting their code (and same could be true with some static functions). Quite often, functions declared static inline do not appear in the optimized code.

    Likewise, some macros might get expanded into some function definitions....

    If compiling with a sufficiently recent version of GCC (e.g. 4.7 or newer) you might make a simple MELT extension for that purpose. The biggest advantage is that it works inside GCC so will really count what GCC is doing... (e.g. after some optimizations).

    Notice that GCC might generate or remove some functions during optimizations (function cloning, function inlining....)

    GCC MELT is obsolete since 2017

提交回复
热议问题