Thread: Check Operating System

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005

    Check Operating System

    Hey, I was wondering how one would go about checking what operating system the user was working in. That's all thanks
    Registered Linux User #380033. Be counted:

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Standard C doesn't care about which OS you're on, so there is no standard way to find out. Not that this is much of a problem, since each OS has a different executable format (not to mention many different processor types), you can't just compile a bit of code and then expect it to execute on any machine.

    When you compile the code, you typically have
    #ifdef DOS
    /* code specific to DOS here */
    #elifdef WIN32
    /* code specific to Win32 here */
    #elif LINUX
    /* code specific to Linux here */
    #error Need another OS
    Unfortunately, there is no standard naming convention for those defines.

    An alternative is to put all the non-portable code into

    In either case, it's a good idea to minimise the amount of code in such places.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Alrighty, thanks. I was just wondering because in a program I'm writing / playing with, I want to clear the screen as the first thing i.e. windows: system("cls"); linux: system("clear"); but its not vital.. so thank you
    Registered Linux User #380033. Be counted:

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. allegro issues
    By mramazing in forum C++ Programming
    Replies: 1
    Last Post: 01-07-2009, 11:56 PM
  2. Check out DEVIL Screensaver System!
    By hartwork in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 08-31-2005, 06:28 PM
  3. Operating system
    By sopranosomega in forum C Programming
    Replies: 6
    Last Post: 10-07-2002, 06:12 AM
  4. idea: operating system
    By roberth9000 in forum Contests Board
    Replies: 6
    Last Post: 09-16-2002, 06:08 AM
  5. Microsoft = The Best Operating System
    By Troll_King in forum A Brief History of
    Replies: 92
    Last Post: 02-08-2002, 01:32 PM