operating system 
Author Message
 operating system

Is there a way I could know which operating system it's compiling on since
some of the header files are only available for UNIX and some are only for
DOS or Windows.

I think there should be ome preprocessor directives or macros that'll help,
right??  How to use those??



Thu, 08 Nov 2001 03:00:00 GMT  
 operating system
Hi,

You should define an environment variable for that. What I do under UNIX is
that I changed my .cshrc file so that it checks the current OS system. This is
because I have different compilers for Linux, Irix and Posix. My .cshrc file
looks like:

if (`uname` == IRIX) then
  setenv OS linux
  setenv COMPILER CC
endif

...

In your makefile - or whatever you use to compile you applications - you have
to use:

$(COMPILER) ... -D $(OS) ...

Now you can use preprocessor directives to selectively include header files
like:

#include <stdio.h>

#ifdef linux
  #include <stdlib.h>
#endif

Under Windows NT there is also an environment variable called OS with the
value 'Windows_NT' ... but you can set this variable yourself for DOS as well.
I don't know which compiler you're using for Windows or DOS but if it is not
gcc or another command line compiler - which usually has the flag '-D' - then
I am sure that there is another way to pass an environment variable.

Hope this help...

Joachim

Quote:

> Is there a way I could know which operating system it's compiling on since
> some of the header files are only available for UNIX and some are only for
> DOS or Windows.

> I think there should be ome preprocessor directives or macros that'll help,
> right??  How to use those??

---------------------------------------------------------------------------

---------------------------------------------------------------------------


Thu, 08 Nov 2001 03:00:00 GMT  
 operating system
I'm now using the opposite way, which is:

#if !defined(__MSDOS__) && !defined(__WIN32__)
#include <something.h>
#endif

it works well, is that okay??


Quote:
>Hi,

>You should define an environment variable for that. What I do under UNIX is
>that I changed my .cshrc file so that it checks the current OS system. This
is
>because I have different compilers for Linux, Irix and Posix. My .cshrc
file
>looks like:

>if (`uname` == IRIX) then
>  setenv OS linux
>  setenv COMPILER CC
>endif

>...

>In your makefile - or whatever you use to compile you applications - you
have
>to use:

>$(COMPILER) ... -D $(OS) ...

>Now you can use preprocessor directives to selectively include header files
>like:

>#include <stdio.h>

>#ifdef linux
>  #include <stdlib.h>
>#endif

>Under Windows NT there is also an environment variable called OS with the
>value 'Windows_NT' ... but you can set this variable yourself for DOS as
well.
>I don't know which compiler you're using for Windows or DOS but if it is
not
>gcc or another command line compiler - which usually has the flag '-D' -
then
>I am sure that there is another way to pass an environment variable.

>Hope this help...

>Joachim


>> Is there a way I could know which operating system it's compiling on
since
>> some of the header files are only available for UNIX and some are only
for
>> DOS or Windows.

>> I think there should be ome preprocessor directives or macros that'll
help,
>> right??  How to use those??

>---------------------------------------------------------------------------

>---------------------------------------------------------------------------



Thu, 08 Nov 2001 03:00:00 GMT  
 operating system

Quote:

>I'm now using the opposite way, which is:

>#if !defined(__MSDOS__) && !defined(__WIN32__)
>#include <something.h>
>#endif

>it works well, is that okay??

No. Because now you are saying that <something.h> exists on all platforms
other than DOS or WIN32.

Feature tests should always be positive. ``If I'm on this platform, or these
platforms, I can use this feature.''

Defaults can be handled by an #else group. ``If I'm on this platform,
use this, otherwise on this other platform, use that, otherwise
this''.



Fri, 09 Nov 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. freeing malloced memory back the operating system.

2. I wrote an operating system

3. I wrote operating system

4. ANNOUNCEMENT: PaulOS Embedded Operating System v1.0

5. Operating system program

6. Operating System Project - Resources management

7. Graphics in different Operating Systems

8. how do I register my dll with NT operating system using VC++5

9. Operating Systems

10. Vaidix: The operating system for the brain

11. C and operating system

12. GUI for simple operating system?

 

 
Powered by phpBB® Forum Software