Thread: system("PAUSE");

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    84

    system("PAUSE");

    Why the following code is not good?

    Code:
    #include <stdlib.h>
    
    int main( void )
    {
      system ( "PAUSE" );
    
      return 0;
    }
    I thought system is from the standard library
    Many thanks....

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    system is, by definition, non-portable, since it passes its argument to the host operating system (if one even exists). And of course, system commands vary from system to system.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    However, the system function is portable. Just the effect is not.

  4. #4
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Like they say - it's not portable, however, using some #ifdefs this can be circumvented.

    Anyway, another reason is that it's very slow, too because it uses the shell to execute the command. Using, for example, "cls" or "clear" instead of clear the screen, and doing so repeatedly, is extremely slow and hogs memory like mad.

    All in all, it's considered bad practice. Besides, both *nix and Windows have API calls to do those things you'd want to do - just a bit more complex than using system.

Popular pages Recent additions subscribe to a feed