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.
2 Answers
Reset to default 0Use 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
.
universal-ctags
but the same problem persists. – Syed Waris Commented Mar 14 at 6:58ctags
from Debian'suniversal-ctags=0+git20200824-1.1
, I get only the definition, not the declaration. Puzzling... – Friedrich Commented Mar 14 at 7:12universal-ctags
you should get only the declaration in thetags
file – Syed Waris Commented Mar 14 at 7:44