I am taking a class and one the expectations are that the source code we submit will compile on our professors computer. Seems reasonable. I really do not want to install windows or use visualization. One of my classmates posted that the code below will do the trick. Any thoughts on this? Can it be improved to be closer to a strict ANSI/ISO c++ compile?
$ g++ -std=c++98 -Wall -Wextra -Werror main.cpp -o outputprogram
My OS is 10.8.x g++ is:
i686-apple-darwin11-llvm-g++-4.2
And gcc is
i686-apple-darwin11-llvm-gcc-4.2:
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 ANSI/ISO
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).
There were probably more, but that's what I can remember at the moment.
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.