Using C or C++ I/O functions

C and C++ make a distinction between types of error output, and whether the output is directed to the MSGFILE destination or to one of the standard stream output devices, stderr or stdout.

Runtime messages and perror() messages are directed to the stderr standard stream output device. The default destination for stderr output is the MSGFILE ddname; you can change this default as discussed below.

Message output issued by a call to the printf() function is directed to stdout. For TSO/E, stdout defaults to the terminal. When running batch (MVS™, IMS™, or TSO/E) or IMS online, stdout attempts by default to open one of several ddnames in the following order of precedence, which is made to open SYSOUT=* as a data set:

  1. SYSPRINT
  2. SYSTERM
  3. SYSERR

You can change the destination of printf() output by redirection. For example, 1>&2 on the command line at routine invocation redirects stdout to the stderr destination.

Table 1 lists the types of C/C++ output, the types of messages associated with them, and the destination of the message output.

Table 1. C and C++ message output
Type of output Type of message Produced by Default destination
MSGFILE output Language Environment messages (CEExxxx) Language Environment unhandled conditions MSGFILE ddname
C library messages C/C++ unhandled conditions (EDCxxxx) MSGFILE ddname
stderr messages perror() messages (EDCxxx) Issued by a call to perror() MSGFILE ddname
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 to printf() stdout

You can control the destination of stderr and stdout output by using the Language Environment MSGFILE runtime option, the C freopen() function, or by invoking redirection services at run time.

Table 2 lists the possible destinations of redirected stderr and stdout standard stream output.

Table 2. C/C++ redirected stream output
Action stderr not redirected stderr redirected to destination other than stdout stderr redirected to stdout
stdout not redirected stdout to itself stdout to itself Both to stdout
stderr to MSGFILE stderr to its other destination n/a
stdout redirected to destination other than stderr stdout to its other destination stdout to its other destination Both to the other stdout destination
stderr to MSGFILE stderr to its other destination n/a
stdout redirected to stderr Both to MSGFILE Both to the other stderr destination When stderr and stdout are redirected to each other (this is not recommended), output from both is directed to whichever was specified first.

For more information about redirecting standard streams in C or C++, see z/OS XL C/C++ Programming Guide.