Why the following code is not good?
I thought system is from the standard libraryCode:#include <stdlib.h> int main( void ) { system ( "PAUSE" ); return 0; }
Many thanks....
Why the following code is not good?
I thought system is from the standard libraryCode:#include <stdlib.h> int main( void ) { system ( "PAUSE" ); return 0; }
Many thanks....
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.
However, the system function is portable. Just the effect is not.
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.