I've the following two .c files
main.c
#include <stdio.h>
int print();
int show(int);
int main()
{
int i = 0;
float x = 1.0;
int y = *((int*)(&x));
print();
i = show(5);
printf("%d", i);
printf("\n%d", y);
return 0;
}
foo.c
#include <stdio.h>
void print()
{
printf("Hello World !!\n");
}
float show()
{
return 1;
}
And here's is my makefile
CC = gcc
CFLAGS = -I. -Wall -pedantic -Wconversion
.PHONY: clean
%.o: %.c
$(CC) -c -o $@ $< $(CFLAGS)
main: main.o foo.o
$(CC) -o main main.o foo.o $(CFLAGS)
clean:
rm -rf *.o
rm -rf main
Here's the output
Hello World !!
1065353216
1065353216
If I build the above, there is absolutely no error. It seems while linking gcc doesn't care that the two functions have different return types and different argument lists.
The second point is that in the function show instead of doing an implicit conversion from float to int, the bit patterns are getting copied, which I've verified using the second printf call.
Why is the above happening? I know this won't happen in g++ due to name mangling, but isn't this a serious problem?