Re: system function to determine OS



John Appleyard wrote:
Since this information is known at compile time, I think the best solution is to define a parameter with the value in, and stick it in a module. Then just uncomment the right one at compile time.

"Clever" ways to do this at run-time are liable to come unstuck when Apple/MS/Linux change the rules without telling you.

INTEGER,PARAMETER :: MAC=1,WINDOWS=2,LINUX=3
INTEGER,PARAMETER :: OS=MAC
!! INTEGER,PARAMETER :: OS=WINDOWS
!! INTEGER,PARAMETER :: OS=LINUX


Interesting. If doing this in C, I would use preprocessor macros and compile my program with cc -DUSING_MAC, cc -DUSING_LINUX, or cc -DUSING_WINDOWS.

My program would contain blocks like

#ifdef USING_MAC
--- do mac stuff ...
#endif

#ifdef USING_LINUX
--- do linux stuff ...
#endif

#ifdef USING_WINDOWS
--- do windows stuff ...
#endif


Is there a Fortran analog to this ?

.



Relevant Pages