Julie said:
I recall hearing/reading about a specific compiler switch to enable such
'safety' warnings, probably not on by default.
For the current VC++ Express 2005 Beta these are the options.
C/C++ COMPILER OPTIONS
-OPTIMIZATION-
/O1 minimize space /O2 maximize speed
/Ob<n> inline expansion (default n=0) /Od disable optimizations (default)
/Og enable global optimization /Oi[-] enable intrinsic functions
/Os favor code space /Ot favor code speed
/Ox maximum optimizations /Oy[-] enable frame pointer
omission
-CODE GENERATION-
/GF enable read-only string pooling /Gm[-] enable minimal rebuild
/Gy[-] separate functions for linker /GS[-] enable security checks
/GR[-] enable C++ RTTI /GX[-] enable C++ EH (same as /EHsc)
/EHs enable C++ EH (no SEH exceptions) /EHa enable C++ EH (w/ SEH
exceptions)
/EHc extern "C" defaults to nothrow
/fp:<except[-]|fast|precise|strict> choose floating-point model:
except[-] - consider floating-point exceptions when generating code
fast - "fast" floating-point model; results are less predictable
precise - "precise" floating-point model; results are predictable
strict - "strict" floating-point model (implies /fp:except)
/GL[-] enable link-time code generation /GA optimize for Windows Application
/Ge force stack checking for all funcs /Gs[num] control stack checking
calls
/Gh enable _penter function call /GH enable _pexit function call
/GT generate fiber-safe TLS accesses /RTC1 Enable fast checks (/RTCsu)
/RTCc Convert to smaller type checks /RTCs Stack Frame runtime checking
/RTCu Uninitialized local usage checks
/clr[:noAssembly|
ure|:safe|
ldSyntax] compile for common language runtime
noAssembly - do not produce an assembly
pure - produce IL-only output file (no native executable code)
safe - produce IL-only verifiable output file
oldSyntax - accept the Managed Extensions syntax from Visual C++
2002/2003
/Gd __cdecl calling convention /Gr __fastcall calling convention
/Gz __stdcall calling convention /GZ Enable stack checks (/RTCs)
/QIfist[-] use FIST instead of ftol()
/arch:<SSE|SSE2> minimum CPU architecture requirements, one of:
SSE - enable use of instructions available with SSE enabled CPUs
SSE2 - enable use of instructions available with SSE2 enabled CPUs
-OUTPUT FILES-
/Fa[file] name assembly listing file /FA[scu] configure assembly listing
/Fd[file] name .PDB file /Fe<file> name executable file
/Fm[file] name map file /Fo<file> name object file
/Fp<file> name precompiled header file /Fr[file] name source browser file
/FR[file] name extended .SBR file
/doc[file] process XML documentation comments and optionally name the
..xdc file
-PREPROCESSOR-
/AI<dir> add to assembly search path /FU<file> forced using
assembly/module
/C don't strip comments /D<name>{=|#}<text> define macro
/E preprocess to stdout /EP preprocess to stdout, no #line
/P preprocess to file /Fx merge injected code to file
/FI<file> name forced include file /U<name> remove predefined macro
/u remove all predefined macros /I<dir> add to include search path
/X ignore "standard places"
-LANGUAGE-
/Zi enable debugging information /Z7 enable old-style debug info
/Zd line number debugging info only /Zp[n] pack structs on n-byte
boundary
/Za disable extensions /Ze enable extensions (default)
/Zl omit default library name in .OBJ /Zg generate function prototypes
/Zs syntax check only /vd{0|1} disable/enable vtordisp
/vm<x> type of pointers to members
/Zc:arg1[,arg2] C++ language conformance, where arguments can be:
forScope[-] - enforce Standard C++ for scoping rules
wchar_t[-] - wchar_t is the native type, not a typedef
/ZI enable Edit and Continue debug info
/openmp enable OpenMP 2.0 language extensions
-MISCELLANEOUS-
@<file> options response file /?, /help print this help message
/c compile only, no link
/errorReport:{prompt|queue} Send internal compiler error report to
Microsoft:
prompt - prompts to send report (development environment default)
queue - At next system logon, prompts to send report (command line
default)
/FC use full pathnames in diagnostics /H<num> max external name length
/J default char type is unsigned /nologo suppress copyright message
/showIncludes show include file names /Tc<source file> compile file as .c
/Tp<source file> compile file as .cpp /TC compile all files as .c
/TP compile all files as .cpp /V<string> set version string
/w disable all warnings /wd<n> disable warning n
/we<n> treat warning n as an error /wo<n> issue warning n once
/w<l><n> set warning level 1-4 for n /W<n> set warning level (default
n=1)
/Wall enable all warnings /WL enable one line diagnostics
/WX treat warnings as errors /Yc[file] create .PCH file
/Yd put debug info in every .OBJ /Yl[sym] inject .PCH ref for
debug lib
/Yu[file] use .PCH file /Y- disable all PCH options
/Zm<n> max memory alloc (% of default) /Wp64 enable 64 bit porting warnings
-LINKING-
/LD Create .DLL /LDd Create .DLL debug library
/LN Create a .netmodule /F<num> set stack size
/link [linker options and libraries] /MD link with MSVCRT.LIB
/MT link with LIBCMT.LIB /MDd link with MSVCRTD.LIB debug lib
/MTd link with LIBCMTD.LIB debug lib
-------------------------------------------------------------------------
For the code:
#include <cstring>
#include <iostream>
int main()
{
using namespace std;
char *s= "Testing std::strlen()";
cout<<strlen(s)<<"\n";
}
With C:\c>cl /Wall /EHsc temp.cpp
we get (it compiles successfully):
temp.cpp
C:\Program Files\Microsoft Visual Studio 8\VC\include\wchar.h(115) :
warning C4820: '_wfinddata64i32_t' : '4' bytes padding added after data
member '_wfinddata64i32_t::attrib'
C:\Program Files\Microsoft Visual Studio 8\VC\include\wchar.h(120) :
warning C4820: '_wfinddata64i32_t' : '4' bytes padding added after data
member '_wfinddata64i32_t::name'
C:\Program Files\Microsoft Visual Studio 8\VC\include\wchar.h(124) :
warning C4820: '_wfinddata64_t' : '4' bytes padding added after data
member '_wfinddata64_t::attrib'
C:\Program Files\Microsoft Visual Studio 8\VC\include\wchar.h(486) :
warning C4820: '_stat32' : '2' bytes padding added after data member
'_stat32::st_gid'
C:\Program Files\Microsoft Visual Studio 8\VC\include\wchar.h(502) :
warning C4820: 'stat' : '2' bytes padding added after data member
'stat::st_gid'
C:\Program Files\Microsoft Visual Studio 8\VC\include\wchar.h(520) :
warning C4820: '_stat32i64' : '2' bytes padding added after data member
'_stat32i64::st_gid'
C:\Program Files\Microsoft Visual Studio 8\VC\include\wchar.h(521) :
warning C4820: '_stat32i64' : '4' bytes padding added after data member
'_stat32i64::st_rdev'
C:\Program Files\Microsoft Visual Studio 8\VC\include\wchar.h(525) :
warning C4820: '_stat32i64' : '4' bytes padding added after data member
'_stat32i64::st_ctime'
C:\Program Files\Microsoft Visual Studio 8\VC\include\wchar.h(534) :
warning C4820: '_stat64i32' : '2' bytes padding added after data member
'_stat64i32::st_gid'
C:\Program Files\Microsoft Visual Studio 8\VC\include\wchar.h(548) :
warning C4820: '_stat64' : '2' bytes padding added after data member
'_stat64::st_gid'
C:\Program Files\Microsoft Visual Studio 8\VC\include\wchar.h(549) :
warning C4820: '_stat64' : '4' bytes padding added after data member
'_stat64::st_rdev'
C:\Program Files\Microsoft Visual Studio 8\VC\include\crtdbg.h(926) :
warning C4619: #pragma warning : there is no warning number '4507'
C:\Program Files\Microsoft Visual Studio 8\VC\include\typeinfo(53) :
warning C4820: 'type_info' : '3' bytes padding added after data member
'type_info::_m_d_name'
C:\Program Files\Microsoft Visual Studio 8\VC\include\xiosbase(540) :
warning C4640: '_Stub' : construction of local static object is not
thread-safe
C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(832) :
warning C4710: 'std::string std::_Locinfo::_Getname(void) const' :
function not inlined
C:\Program Files\Microsoft Visual Studio
8\VC\include\xlocinfo(84) : see declaration of 'std::_Locinfo::_Getname'
C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(832) :
warning C4710: 'std::string std::locale::name(void) const' : function
not inlined
C:\Program Files\Microsoft Visual Studio
8\VC\include\xlocale(378) : see declaration of 'std::locale::name'
C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(832) :
warning C4710: 'std::locale std::ios_base::getloc(void) const' :
function not inlined
C:\Program Files\Microsoft Visual Studio
8\VC\include\xiosbase(407) : see declaration of 'std::ios_base::getloc'
C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(832) :
warning C4710: 'std::basic_string<_Elem,_Traits,_Ax>
std::numpunct<_Elem>::falsename(void) const' : function not inlined
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
C:\Program Files\Microsoft Visual Studio
8\VC\include\xlocnum(67) : see declaration of
'std::numpunct<_Elem>::falsename'
with
[
_Elem=char
]
C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(832) :
warning C4710: 'std::basic_string<_Elem,_Traits,_Ax>
std::numpunct<_Elem>::truename(void) const' : function not inlined
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
C:\Program Files\Microsoft Visual Studio
8\VC\include\xlocnum(72) : see declaration of
'std::numpunct<_Elem>::truename'
with
[
_Elem=char
]
C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(832) :
warning C4710: 'std::string std::numpunct<_Elem>::do_grouping(void)
const' : function not inlined
with
[
_Elem=char
]
C:\Program Files\Microsoft Visual Studio
8\VC\include\xlocnum(135) : see declaration of
'std::numpunct<_Elem>::do_grouping'
with
[
_Elem=char
]
C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(832) :
warning C4710: 'std::basic_string<_Elem,_Traits,_Ax>
std::numpunct<_Elem>::do_falsename(void) const' : function not inlined
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
C:\Program Files\Microsoft Visual Studio
8\VC\include\xlocnum(140) : see declaration of
'std::numpunct<_Elem>::do_falsename'
with
[
_Elem=char
]
C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(832) :
warning C4710: 'std::basic_string<_Elem,_Traits,_Ax>
std::numpunct<_Elem>::do_truename(void) const' : function not inlined
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
C:\Program Files\Microsoft Visual Studio
8\VC\include\xlocnum(145) : see declaration of
'std::numpunct<_Elem>::do_truename'
with
[
_Elem=char
]
C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(832) :
warning C4710: 'std::string std::numpunct<_Elem>::grouping(void) const'
: function not inlined
with
[
_Elem=char
]
C:\Program Files\Microsoft Visual Studio
8\VC\include\xlocnum(62) : see declaration of
'std::numpunct<_Elem>::grouping'
with
[
_Elem=char
]
Microsoft (R) Incremental Linker Version 8.00.41013
Copyright (C) Microsoft Corporation. All rights reserved.
/out:temp.exe
temp.obj