views:

706

answers:

4

Why I get the following warning for the following code :)

Code:

_stprintf(m_szFileNamePath,_T("%s"),strFileName);

warning C4996: '_swprintf': swprintf has been changed to conform with the ISO C standard, adding an extra character count parameter. To use traditional Microsoft swprintf, set _CRT_NON_CONFORMING_SWPRINTFS.

I know _strprintf is a macro which if _UNICODE is defined will evaluate to _swprintf else it will be sprintf.

Now what is this _swprintf. There is a function swprintf, but why is _stprintf evaluating to _swprintf instead of swprintf.

What is the difference b/w the _xxx and xxx functions?

EDIT:

Okay there are two definitions for the UNICODE version of _stprintf, which one is included?

The one in tchar.h or strsafe.h?

+2  A: 

http://msdn.microsoft.com/en-us/library/ybk95axf%28VS.80%29.aspx

swprintf is a wide-character version of sprintf; the pointer arguments to swprintf are wide-character strings. Detection of encoding errors in swprintf may differ from that in sprintf. swprintf and fwprintf behave identically except that swprintf writes output to a string rather than to a destination of type FILE, and swprintf requires the count parameter to specify the maximum number of characters to be written. The versions of these functions with the _l suffix are identical except that they use the locale parameter passed in instead of the current thread locale.

In Visual C++ 2005, swprintf conforms to the ISO C Standard, which requires the second parameter, count, of type size_t. To force the old nonstandard behavior, define _CRT_NON_CONFORMING_SWPRINTFS. In a future version, the old behavior may be removed, so code should be changed to use the new conformant behavior.

suszterpatt
Why is it giving the warning then?
hab
Doesn't the warning explain that? Because they have changed the behavior. People generally like to know when code doesn't do what they expect. ;)
jalf
A: 

Microsoft provides its own extension of CRT _swprintf - is not compatible (for example) with unix

Dewfy
A: 

Microsoft (used to?) prefix otherwise widely available non-win32 functions that were not part of the C standard with underscore.

nos
Okay there are two definitions for the UNICODE version of _stprintf, which one is included????The one in tchar.h or strsafe.h?
hab
A: 

_stprintf(m_szFileNamePath,256,_T("%s"),strFileName);

fly931