Check Operating System

This is a discussion on Check Operating System within the C Programming forums, part of the General Programming Boards category; Hey, I was wondering how one would go about checking what operating system the user was working in. That's all ...

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    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: http://counter.li.org

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,588
    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
    Code:
    #ifdef DOS
    /* code specific to DOS here */
    #elifdef WIN32
    /* code specific to Win32 here */
    #elif LINUX
    /* code specific to Linux here */
    #else
    #error Need another OS
    #endif
    Unfortunately, there is no standard naming convention for those defines.

    An alternative is to put all the non-portable code into
    porting_dos.c
    porting_win32.c
    porting_linux.c

    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    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: http://counter.li.org

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, 10: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 Cprogramming.com
    Replies: 92
    Last Post: 02-08-2002, 12:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21