I've seen a few questions addressing this general topic, but I'm still unsure exactly what the correct approach is for ISO C, and how that may or may not vary from GNU C.
If I have some function inline void foo()
in file.h
defined with the inline
keyword, should I also declare that function in file.c
as extern void foo();
? Assume that multiple .c
files will include file.h
.
From what I've read the answer seems to be "yes" and have something to do with how the compiler looks for definitions emitted by other translation units, but to be honest I don't fully understand the implications.
I'm working on a project right now that has a lot of functions declared inline
within the header files, and none of those functions are declared in the corresponding .c
files. Everything compiles without gcc complaining, but is this approach actually correct?
in file.h defined
should I also declare
Are you mixing terms "function definition" and "function declaration"?but is this approach actually correct?
are those function defined or declared? Are theystatic
? – Stenograph.c
file to force emission of the function symbol in at least one TU. Without this no symbol for the function will ever be emitted. – Olives.h
and theextern inline
declaration in exactly one.c
to make a working C program with a non-staticinline
function defined in a header and thus able to actually inline. – Venesection