I have the following files:
main.c :
int f(void);
int main(void)
{
f();
return 0;
}
f.c:
char *f = "linker";
GNUMakefile:
CC = gcc
CFLAGS = -Wall -g
all: main
main: main.o f.o
main.o: main.c
f.o: f.c
clean:
rm -rf *.o main
When running the makefile I get no compilation warnings/errors. Why?
Because you lied to the compiler … and it trusts you.
In main.c you told the compiler
fis a function (declaration / prototype), butfis, in fact, a pointer to a (unmodifiable) character array of length 7 defined in f.c (definition).Don’t lie to the compiler.