2
//main.c  
#include "stdio.h"
void f(){
    printf("Welcome to emacs's world!");
    return;
}
void call_f(void (*f)()){
    (*f)();
    return;
}
void main(){
    call_f(f);
    return;
}

I use cscope to find the definition of function "call_f", but have no result, the cscope can't find the definition of "call_f".
I change the argument type of function "call_f" to another type except for a function pointer.

#include "stdio.h"
void f(){
    printf("Welcome to emacs's world!");
    return;
}
void call_f(/* void (*f)() */void){
//    (*f)();
    f();
    return;
}
void main(){
//    call_f(f);
    call_f(void);
    return;
}

Then cscope can find the definition of function "call_f". Is that a bug?

董泽锋
  • 105
  • 9

1 Answers1

5

Yes, this is a bug. Cscope doesn't implement a full C language parser. Instead it just uses a scanner with a lot of quirks.

For example, cscope also isn't able to recognize function calls/declarations if the opening argument bracket is on the next line like this:

fn_foo
    (arg1, arg2);

The bug you found is even documented in cscope's man page:

Nor does it recognize function definitions with a function pointer argument

    ParseTable::Recognize(int startState, char *pattern,
      int finishState, void (*FinalAction)(char *))
    {
      ...
    }
maxschlepzig
  • 35,645
  • 14
  • 145
  • 182