How should I compile source code in c++ on a mac to ensure it will
compile correctly in Windows Visual Studio Complier while adhering to
You really can't do that. Not possible. Compilers behave slightly
differently in different places and sometimes that leads to compilation
failures and/or slightly different program behavior. When it comes to
Microsoft Compiler, it can happily compile code that baffles G++(typically
templates), and vice versa, and that's even if you don't take into account
non-standard function and extensions. So, the only sure way to test
compiler is to use that compiler.
Issues I personally run into when developing code that is supposed to
work with g++/cl.exe (cl.exe == microsoft compiler).
- Compared to cl.exe, g++ is insanely slow, at least on windows. (2..5x
- g++ sometimes can't compile template constructs cl.exe processes just
- cl.exe cannot process insanely large string constants (compared to
- cl.exe (VS2008 express) cannot detect UTF8 encoding without a BOM.
- Mixing encodings with cl.exe (when OS uses encoding A, source file is
in encoing B, and you want to display wchar_t string using function that
requires encoidng C) is a nightmare.
- C standard library functions are different on cl.exe/g++. One compiler
can have a function that isn't present on another compiler (some of them
don't have some string *ncmp function), compiler might have non-standard
functions that isn't present in another compiler (strcpy_s), and certain
functions might behave differently with certain arguments (sprintf with
- passing -Wall to cl.exe produces thousands of warnings for harmless
code if windows.h is included. Those warnings cannot be fixed.
There were probably more, but that's what I can remember at the
I really do not want to install windows
You could try using Wine to install Microsoft Compiler onto MacOS. I would
expect that you won't be able to install Visual Studio IDE using wine (your mileage may wary),
but you should be able to run command line-only microsoft compiler that is
shipped with Windows Driver Kit. To use compiler this way you must be
really familiar with it, though, so installing windows into virtual machine
will be probably much easier.