S
subramanian100in
Suppose I have
#include <stdio.h>
#include <string.h>
size_t strlen(const char *str)
{
printf("from strlen - %s\n", str);
return 0; // return some dummy value
}
int main(void)
{
printf("%zu\n", strlen("test message"));
return 0;
}
When I compile this program under Redhat Linux with the command
gcc -std=c99 -pedantic -Wall -Wextra x.c
There is no linker error which I expected because of multiple strlen()
definitions - one in this file and the other in the standard library.
Am I wrong ?
However if I have another file say y.c containing the another
definition for strlen(), and compile
gcc -std=c99 -pedantic -Wall -Wextra x.c y.c
I get linker error for multiple definitions for strlen().
I am unable to understand the difference. Kindly explain.
Thanks
#include <stdio.h>
#include <string.h>
size_t strlen(const char *str)
{
printf("from strlen - %s\n", str);
return 0; // return some dummy value
}
int main(void)
{
printf("%zu\n", strlen("test message"));
return 0;
}
When I compile this program under Redhat Linux with the command
gcc -std=c99 -pedantic -Wall -Wextra x.c
There is no linker error which I expected because of multiple strlen()
definitions - one in this file and the other in the standard library.
Am I wrong ?
However if I have another file say y.c containing the another
definition for strlen(), and compile
gcc -std=c99 -pedantic -Wall -Wextra x.c y.c
I get linker error for multiple definitions for strlen().
I am unable to understand the difference. Kindly explain.
Thanks