gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:55:04 27 4
gpt4 key购买 nike

我想在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

关于c - 如何在C中获取文件中所有函数的范围(即行号)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8067623/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com