Thursday, November 08, 2007

Deprecated String-Conversion Macro

(Nov 8, 2007)

Today, I spent a lot of time trying to nicely rid of some warning messages:
warning C4995: 'gets': name was marked as #pragma deprecated
warning C4995: 'sprintf': name was marked as #pragma deprecated
warning C4995: 'vsprintf': name was marked as #pragma deprecated
warning C4995: 'strcat': name was marked as #pragma deprecated
warning C4995: 'strcpy': name was marked as #pragma deprecated
warning C4995: 'swprintf': name was marked as #pragma deprecated
warning C4995: 'vswprintf': name was marked as #pragma deprecated
warning C4995: 'wcscat': name was marked as #pragma deprecated
warning C4995: 'wcscpy': name was marked as #pragma deprecated

These seems to happen when I try to employ some ATL stuff along with its string conversion features in Visual C++ 2005. Although, I used ATL 7.0 which should not be deprecated, these warning messages still haunted my compile message.

For some unknown reasons, I found that including iostream would automatically be removed. I don't know why, but it does do a trick.

Update: these warning occurs because those deprecated functions are called internally in conversion macros. If we include iostream, some function calls in these macros may be different. Also note that if we explicitly call those deprecated functions, including iostream will do nothing, and we need to explicitly use secured functions, such as sprintf_s instead.

No comments: