pgs
pgs

Reputation: 153

ctags doesn't find one function

I cloned fresh gnulib (git://git.savannah.gnu.org/gnulib.git, Last changes: 23.03.2017) and indexed all files by ctags (Exuberant Ctags 5.9~svn20110310):

ctags -R gnulib

Surprisingly I didn't find any tag of full_write function by grep (I was particulary interested in exactly this function)

grep full_write tags

but this function is declared in a gnulib/lib/full-write.h

extern size_t full_write (int fd, const void *buf, size_t count);

as well as being redefined in a gnulib/lib/full-write.c

# define full_rw full_write

So I am really confused: why didn't ctags identify this particular function?

Upvotes: 2

Views: 2316

Answers (2)

Masatake YAMATO
Masatake YAMATO

Reputation: 1300

To capture declaration, use --C--kinds=+p option.

[jet@localhost ~]$ git clone git://git.savannah.gnu.org/gnulib.git

Cloning into 'gnulib'...
remote: Counting objects: 174685, done.        
remote: Compressing objects: 100% (24750/24750), done.        
remote: Total 174685 (delta 149911), reused 174636 (delta 149876)        
Receiving objects: 100% (174685/174685), 33.95 MiB | 3.97 MiB/s, done.
Resolving deltas: 100% (149911/149911), done.
Checking connectivity... done.
[jet@localhost gnulib]$ ctags --C-kinds=+p -R
[jet@localhost gnulib]$ grep  full_write tags
full_write  lib/full-write.h    /^extern size_t full_write (int fd, const void *buf, size_t count);$/;" p

Upvotes: 3

osgx
osgx

Reputation: 94445

ctags see the declaration, but there can be many declarations. But it see no definition, because real definition looks like definition of C function named full_rw: http://git.savannah.gnu.org/cgit/gnulib.git/tree/lib/full-write.c?id=683b6078961f10905baba598c469402ed0133425#n51

#ifdef FULL_READ
..
# define full_rw full_read
#else
...
# define full_rw full_write
#endif
size_t
full_rw (int fd, const void *buf, size_t count)

ctags have no full c preprocessing capabilities (only several preprocessing heuristics with -I options, documented in http://ctags.sourceforge.net/ctags.html). So ctags can't realize that this full_rw function definition defines something other, the full_write function. There is section of ctags documentation:

CAVEATS

Because ctags is neither a preprocessor nor a compiler, use of preprocessor macros can fool ctags into either missing tags or improperly generating inappropriate tags. Although ctags has been designed to handle certain common cases, this is the single biggest cause of reported problems. In particular, the use of preprocessor constructs which alter the textual syntax of C can fool ctags. You can work around many such problems by using the −I option.

Upvotes: 1

Related Questions