Thread: Detecting the OS

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    55

    Cool Detecting the OS

    Hey all.

    I've just been scouting through the board to try and find a solution to what I thought would be a common problem, but 72 threads later and the only thing close to it, was detecting the Windows version, of which someone suggested using GetVersionEx().

    Anyway, I'd just like to determine the platform type, whether it's win32, Linux, BSD etc. Not real important, but I've got a simple program I've made here which uses system("cls") to clear the screen in DOS. However, I'd like to have a go at being able to clear the screen across several platforms (using preprocessor directives I'd imagine).

    Would it be possible to do this at all? I've seen the methods of clearing the screen in the FAQ, but I wanted to try something like:

    Code:
    #ifdef win32
      // do some funky win32 clear screen stuff
    #else
      #ifdef anotherplatformtype
      // do some different clear screen stuff
      #endif
    #endif
    Thanks in advance.

    John.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    You are pretty much spot on. You just have to get the right preprocessor directives. Just check your compilers help files for conditional compilation and the info you require will be there.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    55
    Thanks dude, I'll check that out now. One thing though, those conditions wouldn't be compiler specific would they? Would partly defeat the point if they were.

    Just wondering anyway, thanks again.

    John.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by John.H
    Thanks dude, I'll check that out now. One thing though, those conditions wouldn't be compiler specific would they? Would partly defeat the point if they were.

    Just wondering anyway, thanks again.

    John.
    There are some directives that are used by multiple compilers....but I dont think there's any real standard...

    If you use a compiler that's ported to multiple platforms, you should fare better. Try Codewarrior (ports for Win32, Mac and Linux) and gcc distros

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting if OS is Windows???
    By Ktulu in forum Windows Programming
    Replies: 2
    Last Post: 11-19-2006, 02:49 AM
  2. Mac OS X Programming
    By Exile in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-06-2005, 03:12 PM
  3. a simple OS
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 06-06-2004, 10:47 PM
  4. Linux OS to Windows OS code
    By sw9830 in forum C Programming
    Replies: 2
    Last Post: 02-28-2003, 03:11 PM
  5. How do they compile code for an OS ?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 49
    Last Post: 03-28-2002, 12:16 AM