Writing Good GNU/Linux
THIS CHAPTER COVERS SOME BASIC TECHNIQUES THAT MOST GNU/Linux program-
mers use. By following the guidelines presented, you’ll be able to write programs that
work well within the GNU/Linux environment and meet GNU/Linux users’ expec-
tations of how programs should operate.
2.1 Interaction With the Execution Environment
When you first studied C or C++, you learned that the special main function is the
primary entry point for a program.When the operating system executes your pro-
gram, it automatically provides certain facilities that help the program communicate
with the operating system and the user.You probably learned about the two parame-
ters to main, usually called argc and argv, which receive inputs to your program.
You learned about the stdout and stdin (or the cout and cin streams in C++) that
provide console input and output.These features are provided by the C and C++
languages, and they interact with the GNU/Linux system in certain ways. GNU/
Linux provides other ways for interacting with the operating environment, too.
Chapter 2 Writing Good GNU/Linux Software
2.1.1 The Argument List
You run a program from a shell prompt by typing the name of the program.
Optionally, you can supply additional information to the program by typing one or
more words after the program name, separated by spaces.These are called command-line
arguments. (You can also include an argument that contains a space, by enclosing the
argument in quotes.) More generally, this is referred to as the program’s argument list
because it need not originate from a shell command line. In Chapter 3,“Processes,”
you’ll see another way of invoking a program, in which a program can specify the
argument list of another program directly.
When a program is invoked from the shell, the argument list contains the entire
command line, including the name of the program and any command-line arguments
that may have been provided. Suppose,