Is there a way to make the msvc compiler as strict as gcc? MSVC lets me do some pretty crazy things that result in hundreds of errors when I compile in linux.
Thanks
Is there a way to make the msvc compiler as strict as gcc? MSVC lets me do some pretty crazy things that result in hundreds of errors when I compile in linux.
Thanks
To get started we'd need the version you are on (for MSVC), what sort of errors you hit (compile time, link time or run time) and so on.
Assuming you are on a relatively current version (MSVC 2008 SP1) and being bugged by compiler errors, I'd suggest the following:
main
and not _tmain
or WinMain
_
-- they are implementation specificchar
wchar_t
A better question would be: Are MSVC, g++, or any other compiler standard compliant, and if so, to the same standard version? You shouldn't rely upon a common set of non-standard behavior. Personally, I'm responsible for over 500KLOC of C++ that compile on both g++ 4.1.x and VC7.1. There can be alot of give and take from both compilers.
Both compilers have either language or library extensions. g++ tends to be better about putting library extensions in a separate namespace. VC, at least older version, not so good. Both have language extensions that are on by default, or can be enabled (or disabled) with compiler switches. You're best disabling all language extensions.
The higher the warning level on each compiler you can set, the better - and don't disregard warnings from either compiler without just reason.
For windows, by default I use the following options: /W3 /wd4355 /wd4805 /wd4710
. I'd like to use /W4
, but 3rd party libs make this level unbearable.
For g++, I use -Wall -Wextra
. I'd also like to use -Wold-style-cast
, but I rely on too many 3rd party libraries that violate this one.
Each compiler warns about different constructs, or warns about them differently. You're best off to pay attention to output from both compilers and find the subset of code between them that produces zero warnings, at as high of a warning level as you can possibly set.
The /Za (Disable Language Extensions) option disables a number of Microsoft-specific keywords and extensions.