This topic is 4337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

In my MFC I have overridden printf like this : in my header : extern "C" int printf(const char* szStr, ...); then in my cpp : extern "C" int printf(const char* szStr, ...) { } The code behaves as i would expect except that I get the following warning for every file that includes the header : warning C4273: 'printf' : inconsistent dll linkage How do i need to specify this to stop this warning?

##### Share on other sites
it happens because you have different linkage for your version of printf. The original function is defined
extern "C" _CRTIMP int _cdecl printf( const char*, ... );

If your using a dll runtime library _CRTIMP is defined as __declspec dllimport). I was under the impression you can't override a C function, but I've been messing around in VC 6 and its letting me do it. However, I haven't been able to resolve this issue because if I make the function signature to be as follows
extern "C" __declspec(dllexport) int _cdecl printf( const char*, ... );

It still complains to me. Since I've edited this post and my previous one about 100 times in 10 minutes, I'm just going to leave the rest of the explaining up to the professionals =)

##### Share on other sites
I'm not sure, but it may simply be that you are including your headers in the wrong order. Ex:

#include "MyPrintf.h"#include <cstdio>

Then the standard header's definition will override yours. Clearly its linking against yours if it's working as you expect. In this case switching the order of the headers (or simply not including the standard header) might work.

##### Share on other sites
Its not the order of the headers. Has anyone solved this problem?

##### Share on other sites
well I dont know much about the nature of the linking problem but a quick fix would just be to call the function something else and use macros to have all the other printf's reference your version. This seems like an ideal solution unless you are trying to do something tricky like have external libraries use your version. Anyway... good luck on it.

##### Share on other sites
My ocde compiles to a lib which is then called by another project so macro's are no good. Surely there is a way to get rid of this warning. Anyone?