I'm trying out some of the solutions to my question.
Say I'm running on a system that implements itoa
. I have this code:
char *my_itoa (int a, char *b, int c)
{
return itoa(a, b, c);
}
char* __attribute__ ((weak)) itoa(int a, char* b, int c)
{
strcpy(b, "No itoa");
}
If I call my_itoa(10, str, 10)
with the above code, puts(str)
gives me "No itoa".
However, if I simply write:
char *my_itoa (int a, char *b, int c)
{
return itoa(a, b, c);
}
and call my_itoa(10, str, 10)
, puts(str)
gives me "10".
My understanding was that __attribute__ ((weak))
would implement a function if it was not already implemented. Is that its true behavior? What's going on here?