MSGFILE considerations

z/OS® XL C/C++ makes a distinction between types of error output according to whether the output is directed to the MSGFILE, to stderr, or to stdout:

Table 1. Output destinations under z/OS XL C/C++
Destination of Output Type of Message Produced by Default Destination
MSGFILE output z/OS Language Environment® messages (CEExxxx) z/OS Language Environment conditions MSGFILE ddname
z/OS XL C/C++ language messages (EDCxxxx) z/OS XL C/C++ unhandled conditions MSGFILE ddname
stderr messages perror() messages (EDCxxxx) Issued by a call, for example, to: perror() MSGFILE ddname (see note 1)
User output sent explicitly to stderr Issued by a call to fprintf() MSGFILE ddname
stdout messages User output sent explicitly to stdout Issued by a call, for example, to: printf() stdout (see note 2)
Notes:
  1. When you are using one of the z/OS UNIX shells, stderr will go to file descriptor 2, which is typically the terminal. See Language Environment Message file operations for more information about z/OS Language Environment message files.
  2. When you are using one of the z/OS UNIX shells, stdout will go to file descriptor 1, which is typically the terminal.

All stderr output is by default sent to the MSGFILE destination, while stdout output is sent to its own destination. When stderr is redirected to stdout, both share the stdout destination. When stdout is redirected to stderr, both share the stderr destination.

If you specified one of the DDs used in the stdout open search order as the DD for the MSGFILE option, then that DD will be ignored in the stdout open search.

Table 2 describes the destination of output to stderr and stdout after redirection has occurred. Whenever stdout and stderr share a common destination, the output is interleaved. The default case is the one where stdout and stderr have not been redirected.

Table 2. z/OS XL C/C++ Interleaved output
  stderr not redirected stderr redirected to destination other than stdout stderr redirected to stdout
stdout not redirected stdout to itself stderr to MSGFILE stdout to itself stderr to its other destination Both to stdout
stdout redirected to destination other than stderr stdout to its other destination stderr to MSGFILE stdout to its other destination stderr to its other destination Both to the new stdout destination
stdout redirected to stderr Both to MSGFILE Both to the new stderr destination stdout to stderr stderr to stdout
z/OS XL C/C++ routes error output as follows:
  • MSGFILE output
    • z/OS Language Environment messages (messages prefixed with CEE)
    • Language messages (messages prefixed with EDC)
  • stderr output
    • perror messages (messages prefixed with EDC and issued by a call to perror())
    • Output explicitly sent to stderr (for example, by a call to fprintf())

    By default, z/OS XL C/C++ sends all stderr output to the MSGFILE destination and stdout output to its own destination. You can change this by using z/OS XL C/C++ redirection, which enables you to redirect stdout and stderr to a ddname, file name, or each other. Unless you have redirected stderr, it always uses the MSGFILE destination. When you redirect stderr to stdout, stderr and stdout share the stdout destination. When you redirect stdout to stderr, they share the stderr destination.