Weak linking (if I'm using the term correctly) is the ability to specify the implementation of a routine twice and have the weakly-linked copy be replaced by the strongly-linked copy. I've used it in gcc and recently stumbled across weak linking in MSVC but I can't find documentation or the compiler switches that enable or disable it.
Consider the example below using printf from <stdio.h>. In this code snippet, the standard printf is replaced with a no-op. You might examine doing this if you link to a library which outputs lots of debugging that you want to turn off, and you don't have access to the source code:
#include <stdio.h>
int __cdecl printf(const char* format, ...)
{
((void*)format);
return 0;
}
int main()
{
printf("hello, world\n"
;
return 0;
}
I compiled and ran this in both C++ and C using the default (Win32 Debug) project settings and received no errors or warnings. Running it gives the expected result: a no-op.
Has anyone else done this? Does anyone know where/if this behavior is documented, and which linker switches control it?
Consider the example below using printf from <stdio.h>. In this code snippet, the standard printf is replaced with a no-op. You might examine doing this if you link to a library which outputs lots of debugging that you want to turn off, and you don't have access to the source code:
#include <stdio.h>
int __cdecl printf(const char* format, ...)
{
((void*)format);
return 0;
}
int main()
{
printf("hello, world\n"

return 0;
}
I compiled and ran this in both C++ and C using the default (Win32 Debug) project settings and received no errors or warnings. Running it gives the expected result: a no-op.
Has anyone else done this? Does anyone know where/if this behavior is documented, and which linker switches control it?