在 7/13/21 5:02 PM, Jonathan Marler 写道:
Thanks for the convenient info. However, when I try to use __attribute__((__weak__)) I get a compiler warning from GCC, i.e.extern __inline__ __attribute__((__weak__)) void foo(void) {} int main(int argc, char *argv[]) { foo(); } $ gcc main.c main.c:2:10: warning: inline function ‘foo’ declared weak [-Wattributes] 2 | void foo(void) {} | ^~~I'm having a hard time figuring out why I get this warning. The info you sent looks consistent with the docs I'm finding, but this warning makes it look like GCC thinks the "weak" attribute is redundant? Note that I still get this same warning if I remove the "extern", so it seems like GCC doesn't like inline and the weak attribute...any idea why?
(Please *Reply to All*.)There must have been reasons why GCC ignores `weak` attribute on inline functions [1]. It might be technical limitation, but I think it makes no sense, because 1) Clang accepts, and 2) decomposing the two attributes actually works as expected [2].
I highly suggest you not play with this inline stuff. It's something very fragile that works by accident; any tiny change could be catastrophic.
[1] https://gcc.godbolt.org/z/ssEz9Gddo [2] https://gcc.godbolt.org/z/Prcenddoc -- Best regards, LIU Hao
OpenPGP_signature
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
