简体   繁体   English

如何获取C中文件中所有函数的范围(即行号)?

[英]How to get the range (i.e., the line number) of all functions in a file in C?

我想得到C中文件中所有函数的开始和结束行号。是否有人知道Linux中是否有一个易于使用的工具用于此目的?

$ ctags -x --c-kinds=f filename.c

This only gives the starting line of each function, but perhaps that is good enough. 这只给出了每个函数的起始行,但也许这就足够了。

If the code was written using fairly common conventions, the function should end with a single line containing } in the first column, so it is fairly easy to get the last line given the first: 如果代码是使用相当常见的约定编写的,那么函数应该在第一列中以包含}的单行结束,因此在第一行中给出最后一行是相当容易的:

awk 'NR > first && /^}$/ { print NR; exit }' first=$FIRST_LINE filename.c

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 斐波那契函数在C中具有大数字(即1000个数字) - Fibonacci function with big number (i.e. 1000 digits) in C 如何拒绝字母数字命令行参数(即 ./main 20x),而不是纯数字参数(即 ./main 20)? (在 C 中) - How can I reject an alphanumeric command-line argument (i.e. ./main 20x), but not a solely numeric one (i.e. ./main 20)? (in C) "如何在 C 中正确计时写入磁盘(即文件)的速度" - How to correctly time speed of writing to a disk (i.e. file) in C 如何计算文件增量,即更改的文件部分 - How to calculate delta on file i.e. changed file portion 如何从父进程获取子进程的状态,即它是停止、继续还是退出? 对于 Linux、C 语言 - How do I get the status of a child process from a parent, i.e. has it stopped, continued, or exited? For Linux, C lang 在 C++ 中,将数字添加到缓冲区(即缓冲区+3)是什么意思? - In C++ what does it mean to add a number to a buffer (i.e. buffer+3)? 如何检查以确保命令行参数的每个字符都是十进制数字(即 0、1、2 等) - how to check to make sure that each character of the command line argument is a decimal digit (i.e., 0, 1, 2, etc.) 在动态 memory 的情况下如何处理二维数组,即在编译时未定义元素的数量 - how to handle 2D array in case of dynamic memory, i.e., number of elements are undefined at compilation time 为什么某些C字符串库函数(即strtok)不接受尚未用malloc分配的char *? - Why won't certain C string library functions (i.e. strtok) accept a char * that hasn't been allocated with malloc? 用lapack计算倒数条件数(即rcond(x)) - Computing the reciprocal condition number with lapack (i.e. rcond(x))
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM