2

It compiles, links and runs without error.

test.c

#include "foo.h"                                                                 

int main()                                                                       
{                                                                                
    foo(4);                                                                      
    foo();                                                                       
    foo("cheese");                                                               
    foo("cheese", 8);                                                            
}

foo.h

#ifndef FOO_H                                                                    
#define FOO_H                                                                    
int foo();                                                                       
#endif

foo.c

#include <stdio.h>                                                               
#include "foo.h"                                                                 

int foo(int a)                                                                   
{                                                                                
    printf("Hello\n");                                                           
}

Compiled with gcc test.c foo.c

Kieren Anderson
  • 488
  • 3
  • 14
  • I made a similar mistake in a project, was surprised that the compiler is ok with this. Makes it hard to find errors. – Kieren Anderson Oct 15 '16 at 05:46
  • Try compiling with `-Wmissing-prototypes` – user3386109 Oct 15 '16 at 05:49
  • The reason is because if your function is defined as `int foo();`, it can accept any number of arguments without error. If you define the function in the header as `int foo(void);`, your example above will generate numerous errors. – PhantomWhiskers Oct 15 '16 at 06:31

0 Answers0