最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

C Code base: ctags only adds entry of the function declaration and not function definition - Stack Overflow

programmeradmin1浏览0评论

I am having C code base on Ubuntu Linux and I am using ctags for code browsing.

$ ctags --version
Exuberant Ctags 5.9~svn20110310, Copyright (C) 1996-2009 Darren Hiebert
  Addresses: <[email protected]>, 
  Optional compiled features: +wildcards, +regex

In my project root, I run the command:
ctags -R *
This generates tags file

ctags only adds entry of the function declaration and not function definition in the tags file.

Suppose my C file is:

static int fxn(int conn_handle, int attr_handle, 
                        int q);


// later

static int fxn(int conn_handle, int attr_handle, 
                        int q) {
                                 
    int ret = 0;
                                 
}


in the tags file, only the declaration of fxn is present. I want both the entries of the fxn tag (declaration + definition) in the tags file. How can I have this ??

I have also tried with universal-ctags but the same problem persists.

FURTHER TESTS:
universal ctags behaves differently on below same codes:

static int fxn(int conn_handle, int attr_handle, int q);


// later

static int fxn(int conn_handle, int attr_handle, int q) {

        int ret = 0;

}

On above code universal-ctags -R * adds only the definition of fxn in the tags file. But if I move the 3rd argument to the next line, ctags behaves differently. See below:

static int fxn(int conn_handle, int attr_handle, 
                        int q);


// later

static int fxn(int conn_handle, int attr_handle, 
                        int q) {
                                 
    int ret = 0;
                                 
}

Now, universal-ctags -R * adds only the declaration of fxn in the tags file.

I am having C code base on Ubuntu Linux and I am using ctags for code browsing.

$ ctags --version
Exuberant Ctags 5.9~svn20110310, Copyright (C) 1996-2009 Darren Hiebert
  Addresses: <[email protected]>, http://ctags.sourcefe
  Optional compiled features: +wildcards, +regex

In my project root, I run the command:
ctags -R *
This generates tags file

ctags only adds entry of the function declaration and not function definition in the tags file.

Suppose my C file is:

static int fxn(int conn_handle, int attr_handle, 
                        int q);


// later

static int fxn(int conn_handle, int attr_handle, 
                        int q) {
                                 
    int ret = 0;
                                 
}


in the tags file, only the declaration of fxn is present. I want both the entries of the fxn tag (declaration + definition) in the tags file. How can I have this ??

I have also tried with universal-ctags but the same problem persists.

FURTHER TESTS:
universal ctags behaves differently on below same codes:

static int fxn(int conn_handle, int attr_handle, int q);


// later

static int fxn(int conn_handle, int attr_handle, int q) {

        int ret = 0;

}

On above code universal-ctags -R * adds only the definition of fxn in the tags file. But if I move the 3rd argument to the next line, ctags behaves differently. See below:

static int fxn(int conn_handle, int attr_handle, 
                        int q);


// later

static int fxn(int conn_handle, int attr_handle, 
                        int q) {
                                 
    int ret = 0;
                                 
}

Now, universal-ctags -R * adds only the declaration of fxn in the tags file.

Share Improve this question edited Mar 14 at 8:19 Syed Waris asked Mar 14 at 6:43 Syed WarisSyed Waris 1,1041 gold badge11 silver badges16 bronze badges 4
  • Note that Exuberant Ctags is no longer maintained. You may consider switching to Universal Ctags. – Friedrich Commented Mar 14 at 6:55
  • @Friedrich I have also tried with universal-ctags but the same problem persists. – Syed Waris Commented Mar 14 at 6:58
  • When I try your example with ctags from Debian's universal-ctags=0+git20200824-1.1, I get only the definition, not the declaration. Puzzling... – Friedrich Commented Mar 14 at 7:12
  • 1 @Friedrich I have changed my example code. Now with universal-ctags you should get only the declaration in the tags file – Syed Waris Commented Mar 14 at 7:44
Add a comment  | 

2 Answers 2

Reset to default 0

Use the latest universal-ctags with extra flags:

uctags -R --c-kinds=+p --fields=+Szn --extras=+q .

Add --C-kinds=+p to the command line. +p means "including the names of prototype declareations".

$ cat foo.c
static int fxn(int conn_handle, int attr_handle, 
                        int q);


// later

static int fxn(int conn_handle, int attr_handle, 
                        int q) {
                                 
    int ret = 0;
                                 
}
$ ctags -o - foo.c
fxn     foo.c   /^static int fxn(int conn_handle, int attr_handle, $/;" f       typeref:typename:int    file:
$ ctags -o - --C-kinds=+p foo.c
fxn     foo.c   /^static int fxn(int conn_handle, int attr_handle, $/;" f       typeref:typename:int    file:
fxn     foo.c   /^static int fxn(int conn_handle, int attr_handle, $/;" p       typeref:typename:int    file:

You can list the supported kinds with --list-kinds=C option:

$ ctags --list-kinds=C
c  classes
d  macro definitions
e  enumerators (values inside an enumeration)
f  function definitions
g  enumeration names
l  local variables [off]
m  class, struct, and union members
n  namespaces
p  function prototypes [off]
s  structure names
t  typedefs
u  union names
v  variable definitions
x  external and forward variable declarations [off]

p is off by default. So you must turn it on explicitly with --C-kinds=+p.

发布评论

评论列表(0)

  1. 暂无评论