fabiensanglard / dc

Driving Compilers
Apache License 2.0
30 stars 15 forks source link

"Transitive Dependency" example is incorrect #2

Closed jkaivo closed 1 year ago

jkaivo commented 1 year ago

In the example of a transitive dependency on the preprocessor page, the error when #include <string.h> is removed from b.h is:

$ clang -o main main.c a.c b.c
main.c:2:3: warning: implicit declaration of function 'printf' is invalid in C99 [-Wimplicit-function-declaration]
1 warning generated.
/usr/bin/ld: /tmp/main-3866ce.o: in function `main':
main.c:(.text+0x20): undefined reference to `printf'  

This is then resolved by adding a #include <string.h> to main.c. However, the C standard library declares printf() in <stdio.h>, not <string.h>. I'm not sure what C library you are using that includes a declaration of printf() when including <string.h>, but that is arguably another instance of a transitive dependency in itself.

I suggest you use a different function, header, or combination in your example.

fabiensanglard commented 1 year ago

Fixed in c6e88b727edf363082b273d202def3561681f914.

I used stdlib, calloc, and free.