Which of these two ways of using static functions is correct?
The second method is correct.
static void afunc(void); is a function declaration. The definition of that function exists somewhere. Since it is also static, if the function is used in this compilation, its definition also needs to be in this compilation of this unit. The function has local linkage.
In the second case, both main.c and afile.c use their locally defined afunc(void).
There is no need to declare to the global namespace that afunc() exist. No other compilation unit needs to know about these local functions of main.c, afile.c
The first is usually incorrect.
The first case "worked" because both main.c and afile.c use and have a locally defined afunc(void).
Should another file foo.c(), use #include "afile.h" and try to call afunc(), it would fail to find a matching local afunc() unless it too has a locally defined
afunc().
"*.h" is more to tell about the functions, objects, defines, types, etc. that "*.c" has for the global namespace to use. Such things that are static are best in top of the "*.c" for its own use and not in "*.h".
The first may be correct in narrow cases.
Example, the "afile.h" declares and defines a small helper function with the intention that whatever "*.c" that includes "afile.h" will get its own local version of afunc(). By making it static, these local afunc() do not collide with a potential global afunc() or each other.