From: Joe M. <jo...@de...> - 2003-07-17 14:57:04
|
Hi all, First, I'm really sorry if this is a FAQ, but I've searched around the mail archives on sf.net and read all the documentation I could get my hands on looking for an explanation of this behaviour to no avail. I'll be only too happy to go do some more reading if it is documented somewhere, though, I just need a push in the right direction. So, here's the strange behaviour I'm seeing. For the record, this is cscope 15.4 compiled from source on Redhat 7.2 using gcc 2.96. I have three files, main.c, fileA.c and fileA.h (reproduced below so everyone can try it out) where fileA.h contains a macro definition and a function prototype. fileA.c contains two functions, the implementation of the prototype from the header file, which contains a call the the macro from the header file, and a second function that calls the first. I hope this covers all the cases I need to illustrate the behaviour I'm seeing. The only strangeness in these files is both fileA.h and fileA.c are being compiled with g++ (regrettably, this isn't something I can change, this requirement has been handed down to me) and we need C linkage for the generated files, so everything is being wrapped in an extern "C" block. More on this later. I build my cscope tags using '-b -u' and then start up the curses UI. If I do a search for any of the symbols "Find this C symbol" everything is good. If I do a search for the global definition of funcB it is correctly located in fileA.h, but if I do a search for the global definition of funcA or funcC cscope is unable to find it anywhere. Further, if I search for functions calling funcA, cscope only tells me it is called in main() and not in funcC. Similarly, if I ask for all functions called by funcC, I get no results. That's the whole of it, I know what the symptoms are, and I know how to fix it in this simple case, simply removing the extern "C" blocks, or using a macro to accomplish the same thing will help cscope, but that's unfortunately not an option in my real project, so I'm hoping there is some way I can convince cscope to find my symbols. Back to the extern "C" silliness. If I take out the extern "C" blocks, of course, everything works correctly. Also, if I define two macros: #define EX_C_START extern "C" { #define EX_C_END } And use those macros in the source, everything still works correctly, the symbols are found successfully, but that does awful things to a different parser being run on the code to generate our documentation. Since it seems the curly braces are what is confusing cscope's parser, is there something I could do to tell it to ignore global scoped blocks that aren't associated with some other construct? A structure, union, typedef, enum, function declaration and so on? Anyway, thanks for your time, everyone. -Joe. /* -----[ main.c * ]------------------------------------------------- */ #include <stdio.h> #include "fileA.h" int main (int argc, char *argv[] ) { funcA(); funcB(); } /* ------------------------------------------------------------------ */ /* -----[ fileA.h ]-------------------------------------------------- */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ void funcA(void); #define funcB() \ do { \ printf("function B\n"); \ } while(0) #ifdef __cplusplus } #endif /* __cplusplus */ /* ------------------------------------------------------------------ */ /* -----[ fileA.c ]-------------------------------------------------- */ #include <stdio.h> #include "fileA.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ void funcA(void) { printf("I'm function A\n"); funcB(); } void funcC(void) { funcA(); } #ifdef __cplusplus } #endif /* __cplusplus */ /* ------------------------------------------------------------------ */ -- Joe MacDonald :wq |