it's far more common and more difficult to guess the following problem (in a header file):
struct something {
type1 var1;
type2 var2;
}
/* EOF */
and when you #include "header.h"
into hello.c
#include <stdio.h>
#include "header.h"
int main(int argc, char **argv)
{
printf("Hello, world
");
}
you get an error e.g.
lcu@europa:~$ gcc main.c
main.c:4:1: error: expected ';', identifier or '(' before 'int'
4 | int main(int argc, char **argv)
| ^~~
and the compiler has got out of header.h
to signal the error in the line of main
function. The thing can be worse if you happen to use legacy code and declare main()
the old way:
main(argc, argv)
char **argv;
{
...
because then, the struct
is a valid type and it is taken as the type returned by main()
and you get (if you get it) the error far below (or no error at all, just a warning):
lcu@europa:~$ gcc main.c
main.c: In function 'main':
main.c:4:1: warning: type of 'argc' defaults to 'int' [-Wimplicit-int]
4 | main(argc, argv)
| ^~~~
In this case, the contents of main.c were:
#include <stdio.h>
#include "header.h"
main(argc, argv)
char **argv;
{
printf("Hello, world
");
}
which is still valid c code.
(these examples were made by gcc, because clang ---the native compiler of freebsd--- detects the EOF in the header file and shows a warning stating that the type was not ended before the end of the include file. But this only happens if the type definition is the last of the file.
Note:
if you declare main as:
#include <stdio.h>
#include "header.h"
main(argc, argv)
int argc;
char **argv;
{
printf("Hello, world
");
}
you get a complete compilation, without even a warning.