ManticMoo.COM -> Jeff's Articles -> Programming Articles -> Visual C++ -> Suppressing deprecation warnings when upgrading to Visual Studio 2005

Suppressing deprecation warnings when upgrading to Visual Studio 2005

by Jeffrey P. Bigham

I was recently tasked with migrating a simple, internal application from VS2003 to VS2005. You would think this would be really simple, and it really wasn't that hard, but there are a few gotcha's that you have to watch out for when doing so.

In its infinite wisdom Microsoft decided that as of Visual Studio 2005, basically all of the standard C functions dealing with strings that rely on an ending NULL character and not a specified length would be deprecated. This means that strcpy, sprintf and strlen are all deprecated to name just a few. In some respects this is a good thing because it might help to convince programmers to use the more secure variations of these standard functions, but, unfortunately, it also causes applications that used to compile cleanly to issue thousands of warnings. Futhermore, switching to the more secure variations of the functions isn't always trivially because to use them you must know the length of the buffers, which might not be easily accessible in many programs not designed for it. And, not to mention, if you use the secure functions you give up all hope of being able to compile your C++ code in Unix.

Avoidance by Suppression

There may be a better way of getting rid of these warning, but until there is I'm just going to suppress them. I want to be as particular as possible with the warnings that I suppress to make sure that I'm not suppressing something useful. Therefore, I picked out the particular warning code associated with these warnings, code 4996, and suppress only warnings of that type.

To suppress these warnings simply add the following compiler directive:

/wd4996
to your commandline options.

In Visual Studio this can be found in the Properties of your project, under C/C++, in the Commandline option.

List of newly deprecated functions in VS2005 and their secure alternative

FunctionSecure Alternative
access_access, _access_s
cabs_cabs
cgets_cgets, _cgets_s
chdir_chdir
chmod_chmod
chsize_chsize, _chsize_s
close_close
cprintf_cprintf, _cprintf_s
cputs_cputs
creat_creat
cscanf_cscanf, _cscanf_s
cwait_cwait
dup_dup
dup2_dup2
ecvt_ecvt, _ecvt_s
eof_eof
execl_execl
execle_execle
execlp_execlp
execlpe_execlpe
execv_execv
execve_execve
execvp_execvp
execvpe_execvpe
fcloseall_fcloseall
fcvt_fcvt, _fcvt_s
fdopen_fdopen
fgetchar_fgetchar
filelength_filelength
fileno_fileno
flushall_flushall
fputchar_fputchar, _fputwchar
gcvt_gcvt, _gcvt_s
getch_getch
getche_getche
getcwd_getcwd, _wgetcwd
getpid_getpid
getw_getw
hypot_hypot
inp_inp
inpw_inpw
isascii__isascii
isatty_isatty
iscsym__iscsym
iscsymf__iscsymf
itoa_itoa, _itoa_s
j0_j0
j1_j1
jn_jn
kbhit_kbhit
lfind_lfind, _lfind_s
locking_locking
lsearch_lsearch, _lsearch_s
lseek_lseek
ltoa_ltoa, _ltoa_s
memccpy_memccpy
memicmp_memicmp
mkdir_mkdir
mktemp_mktemp, _mktemp_s
open_open
outp_outp
outpw_outpw
putch_putch
putenv_putenv, _putenv_s
putw_putw
read_read
rmdir_rmdir
rmtmp_rmtmp
setmode_setmode
sopen_sopen, _sopen_s
spawnl_spawnl
spawnle_spawnle
spawnlp_spawnlp
spawnlpe_spawnlpe
spawnv_spawnv
spawnve_spawnve
spawnvp_spawnvp
spawnvpe_spawnvpe
strcmpi_stricmp
strdup_strdup
stricmp_stricmp
strlwr_strlwr, _strlwr_s
strnicmp_strnicmp
strnset_strnset, _strnset_s
strrev_strrev
strset_strset, _strset_s
strupr_strupr, _strupr_s
swab_swab
tell_tell
tempnam_tempnam
toascii__toascii
tzset_tzset
ultoa_ultoa, _ultoa_s
umask_umask, _umask_s
ungetch_ungetch
unlink_unlink
wcsdup_wcsdup
wcsicmp_wcsicmp
wcsicoll_wcsicoll
wcslwr_wcslwr, _wcslwr_s
wcsnicmp_wcsnicmp
wcsnset_wcsnset, _wcsnset_s
wcsrev_wcsrev
wcsset_wcsset, _wcsset_s
wcsupr_wcsupr, _wcsupr_s
write_write
y0_y0
y1_y1
yn_yn

ManticMoo.COM -> Jeff's Articles -> Programming Articles -> Visual C++ -> Suppressing deprecation warnings when upgrading to Visual Studio 2005