This question has already been answered:

#include <stdio.h> void lol (void) { printf("356"); hello(); return; } void gutenTag (void) { printf("Guten Tag!"); return; } void hello (void) { printf("Hello, world!"); gutenTag(); return; } void main (void) { hello(); lol(); lol(); hello(); return; } 

c99

console.txt

 C:\c>gcc hello2.c -o hello2.exe hello2.c: In function 'lol': hello2.c:7:2: warning: implicit declaration of function 'hello' [-Wimplicit-function-declaration] hello(); ^ hello2.c: At top level: hello2.c:20:6: warning: conflicting types for 'hello' void hello (void) ^ hello2.c:7:2: note: previous implicit declaration of 'hello' was here hello(); ^ ` 

Reported as a duplicate by members of aleksandr barakin , Community Spirit 1 Feb '17 at 21:24 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • in lol use hello before its announcement - Sublihim

2 answers 2

You hello() in lol() used before the announcement.

Either arrange them in gutenTag-hello-lol order, or before lol declare

 void hello(); 
  • Then it is better to void hello(void) - if you make an announcement, then with a prototype . This is not to mention the fact that non-prototype function declarations are in the С obsolescent feature . - AnT

Up to the c99 standard, it was allowed to use (call) functions without explicitly declaring them. In this case, the presence of a call to such a function f() in the code was perceived by the compiler in the same way as if earlier a point of use would be a type declaration:

 int f(); 

Those. a function is assumed that returns an int and accepts an unknown but fixed number of arguments. And, for example, this code:

 int main(void) { f(1, 2); return 0; } int f(int a, int b) { return 0; } 

is quite valid for c89. But in c99 this shop was closed, and the following strict standards compilers should prohibit such code. However, for compatibility, they are often limited to warnings (in your case, just a warning, not an error). To eliminate such problems, you need to add a preliminary declaration of the function before calling it (or just transfer the entire implementation above).

  • And extern here and? Why not just int f(); ? The code of your example does not contain constraint violations, but nonetheless gives rise to indefinite behavior, which can also be expressed in the refusal of the compiler to compile the code. Is the code with UB "valid" - a separate question. - AnT
  • @AnT extern for functions is optional, but it doesn't spoil anything. About the number of parameters taken into account. About constraint violations I would like to hear an explanation. - αλεχολυτ
  • "Constraint violation" is the reason for the "compilation error". - AnT