0

If I implement function as weak function in this way for example:

a.h:

int func1();

a.c:

#include "a.h"
__attribute__((weak)) int func1() {
  ...
}

Is it possible to implement this function in another file, for example X.c as a static function? for example:

#include "a.h"
static int func1(void) {   <<----------- error
  ...
}

I tried to do it but I got this error:

error: static declaration of `func1` follows non-static declaration

But I'm not sure why I can't to do that.. After all, this is a static function only in X.c file..

Brian61354270
  • 8,690
  • 4
  • 21
  • 43
  • Yes, but it uses the same name as the function you just imported using `#include "a.h"` I'd say, at best, this is just confusing. – Robert Harvey Mar 26 '23 at 19:20

1 Answers1

0

You are including the .h file with some prototype of the function func1

Then you try to define it in the file wich includes that definition. The definition and declaration do not match. The compiler doesn't know which one to use and it is complaining about it. You need to have the same prototype and definition - otherwise, it will fail.

0___________
  • 60,014
  • 4
  • 34
  • 74