z/TPF

z/TPF

z/TPF

The z/TPF group is dedicated to sharing news, knowledge, and insights about the z/TPF product family. Consisting of IBMers and users, this community collaborates to advance the potential of high-volume, high-throughput transaction technology.

 View Only

Optional warning when including iostream (PJ47102)

By JT Plotzke posted 08/16/23 11:33 AM

  

Including the <iostream> header in a z/TPF application incurs performance overhead even if the application does not use any of the <iostream> header functionality. The optional warning when including <iostream> (PJ47102) provides the capability for you to easily identify uses of the <iostream> header in your applications at compiler time.

The C++ standard template library provides I/O capabilities to stdin and stdout via global stream objects (cin, cout, etc.) within the <iostream> header. To use these objects, they must first be initialized. By default, <iostream> chooses to statically initialize them up front, whenever an application first includes the header, such that they are ready for any future use. This drives noticeable overhead at runtime, and in particular unnecessary overhead when the application does not actually intend to use the global objects later in its code. Because of this runtime overhead, the use of <iostream> on z/TPF has always been discouraged.

For GCC 4.6, a z/TPF-specific modification was made to CPP1 to defer instantiation of these objects until actual use. This modification was purposely not carried forward to the new version of CPP1 with GCC 7 as the update does not adhere to C++ standards. The overhead saved is also only applicable in instances where an application does not actually use the contents of the header it includes, which only rewards bad programming practices. However intentional and necessary the runtime change was, its potential impact was not clearly relayed as a migration consideration from GCC 4.6 to GCC 7.

With this support, the compiler can now inform you of these instances at compile time when you use GCC 7 or Dignus 2.25. By default, the warning message is disabled to mirror the prior experience at these compiler levels. However, enabling the warning globally while subsequently disabling the warning on an application-by-application basis is the recommended best practice. You can toggle the setting by using the _TPF_WARN_IOSTREAM macro definition.

Recommended use

By default, the warning is disabled in tpftools/include_ztpf/maketpf.rules_set_flags_tpf_gcc_7 and maketpf.rules_set_flags_tpf_dcc via:

CXXFLAGS1 += -D_TPF_WARN_IOSTREAM=0

We recommend overriding this to globally enable the warning in tpftools/include_ztpf_user/maketpf.rules_set_flags_tpf_gcc_7 or maketpf.rules_set_flags_tpf_dcc via:

CXXFLAGS1 += -D_TPF_WARN_IOSTREAM=1

Once globally enabled, you will start receiving the following warning for any application that includes <iostream>:

warning: <iostream> is included by this application. Compile with -D_TPF_WARN_IOSTREAM=0 if this is intentional.

To address this, take one of the following actions:

  1. Remove the use of the <iostream> header file from your application. The most straightforward alternative would be to use APIs from <cstdio> instead.
  2. If not possible, explicitly disable the warning for just that application (e.g. ABCD) in its .mak file (e.g. abcd.mak) via:
    CXXFLAGS_ABCD += -U_TPF_WARN_IOSTREAM -D_TPF_WARN_IOSTREAM=0

Additional information

For more information about APAR PJ47102, see the APEDIT.

0 comments
11 views

Permalink