Is there a way to detect the compiler being used? Namely, is
there a way to have lines of code that are included or ignored
by specific compilers. Or, better, finding certain compiler
behaviors to use/ avoid. For example, Visual Studio
automatically inserts a system("PAUSE") statement. Is there
any way to detect that VS is being used and not compile the
equivalent line in my program?
As others have pointed out, almost every compiler pre-defines
some preprocessor symbols to identify itself, hoping that they
won't conflict with those of any other compiler. But a more
pertinant question, in my mind, would be why you would want to
depend on this. First, of course, most code (99% or more)
should be written so that it doesn't matter. And for that that
does, the symbols are generally defined in a way that only
allows you to use #ifdef, which of course makes the code rapidly
unreadable and unmaintainable. What you really want is 1) one
common symbol which will resolve to the name of a directory, so
you can build up includes to get the right headers *and* system
dependent code, and possibly 2) common symbols which define the
presence or absense of specific features, or how they work (e.g.
things like GB_allowedDirectorySeparators, which can be either
"/" or "\\/"---or maybe something completely different on a
platform I don't currently target). In my experience, the best
way to handle the first is in the command line in the make
file---that needs to be adopted to each compiler anyway, and
adding something like /Dsyst=windows to it doesn't really cause
any additional problems. Or---what I actually use---you can add
a /I option with the directory where you put the system specific
headers. And the second is easily handled once you've done
this; you pick up the defined from a system dependent header.
As for a tool which automatically inserts code which you don't
want, the simple answer is: don't use it.