Incompatibilities Between
ISO C and ISO C++


By David R. Tribble
david@tribble.com

Revision 1.0, 2001-08-05

Contents



Introduction

The C programming language began to be standardized some time around 1985 by the ANSI X3J9 committee. Several years of effort went by, and in 1989 ANSI approved the new standard. An ISO committee ratified it a year later in 1990 after adding an amendment dealing with internationalization issues. The 1989 C standard is known officially as ANSI/ISO 9899-1989, Programming Languages - C, and this document refers to the 1989 C standard as C89. The 1990 ISO revision of the standard is known officially as ISO/IEC 9899-1990, Programming Languages - C, which is referred to in this document as "C90".

The next version of the C standard was ratified by ISO in 1999. Officially know as ISO/IEC 9899-1999, Programming Languages - C, it is referred to in this document as "C99".

The C++ programming language was based on the C programming language as it existed shortly after the ANSI C standardization effort had begun. Around 1995 an ISO committee was formed to standardize C++, and the new standard was ratified in 1998, which is officially known as ISO/IEC 14882-1998, Programming Languages - C++. It is referred to in this document as "C++98" or simply as "C++".

Though the two languages share a common heritage, and though the designers involved in the standardization processes for each language tried to keep them as compatible as possible, some incompatibilities unavoidably arose. Once the programmer is aware of these potential problem spots, they are easy, for the most part, to avoid when writing C code.

When we say that C is incompatible with C++ with respect to a specific language feature, we mean that a C program that employs that feature either is not valid C++ code and thus will not compile as a C++ program, or that it will compile as a C++ program but will exhibit different behavior than the same program compiled as a C program. In other words, an incompatible C feature is valid as C code but not as C++ code. All incompatibilities of this kind are addressed in this document. Avoiding these kinds of incompatibilities allows the programmer to write correct C code that is intended to interact with, or be compiled as, C++ code.

Another form of incompatible feature is one that is valid when used in a C++ program but is invalid in a C program. We call this an incompatible C++ feature. Huge portions of the C++ language fall into this category (e.g., classes, templates, exceptions, references, member functions, anonymous unions, etc.), so very few of these kinds of incompatibilities are addressed in this document.

Yet another form of incompatible feature occurs when a C++ program uses a feature that has the same name as a C90 feature but which has a different usage or meaning in C. This document covers these kinds of incompatibilities.

This document lists only the incompatibilities between C99 and C++98. (Incompatibilities between C90 and C++ have been documented elsewhere; see Appendix B of Stroustrup [STR], for example.)

New additions to the C99 standard library are also not addressed in this document unless they specifically introduce C++ incompatibilities.


C++ versus C

As discussed in the Introduction, no attempt is made in this document to cover incompatible C++ features, i.e., features of the C++ language or library that are not supported in C. Huge portions of C++ and its library fall into this category. A partial list of these features includes:

  • anonymous unions
  • classes
  • constructors and destructors
  • exceptions and try/catch blocks
  • external function linkages (e.g., extern "C")
  • function overloading
  • member functions
  • namespaces
  • new and delete operators and functions
  • operator overloading
  • reference types
  • standard template library (STL)
  • template classes
  • template functions


  • Changes to C99 versus C++98

    The following items are incompatibilities between C90 and C++98, but have since been changed in C99 so that they no longer cause problems between the two languages.



    C99 versus C++98

    The following items comprise the differences between C99 and C++98. Some of these incompatibilities existed between C89 and C++98 and remain unchanged between C99 and C++98, while others are new features that were introduced into C99 that are incompatible with C++98.

    Note that features that are specific to C++ and which are not legal C (e.g., class member function declarations) are not included in this section; only language features that are common to both C and C++ are discussed. Most of the features are valid as C but invalid as C++.

    Some of these features are likely to be implemented as extensions by many C++ compilers in order to be more compatible with C compilers.


    References

    [C89]
    Programming Languages - C
    ANSI/ISO 9899:1989, 1989,
    Available at www.ansi.org.

    [C90]
    Programming Languages - C
    (with ISO amendments)
    ISO/IEC 9899:1990, 1990, ISO/IEC JTC1/SC22/WG14.
    Available at www.ansi.org.

    [C99]
    Programming Languages - C
    ISO/IEC 9899:1999, 1999, ISO/IEC JTC1/SC22/WG14.
    Available at www.ansi.org.

    [C++98]
    Programming Languages - C++
    ISO/IEC 14882:1998(E), 1998-09-01, 1st ed., ISO/IEC JTC1/SC22.
    Available at www.ansi.org.

    [STR]
    The C++ Programming Language, Appendix B - Compatibility
    Bjarne Stroustrup.
    Third ed., 1997, AT&T.
    Available in PDF format at www.research.att.com/~bs/3rd_compat.pdf.


    Acknowledgments

    My thanks to the the people who gave helpful comments on early drafts of this document, especially to the following individuals who emailed me suggestions and corrections or posted comments on the comp.std.c and comp.std.c++ newsgroups:


    Revision History

    1.0, 2001-08-05
    Completed revision.

    0.12, 2000-11-13
    Minor corrections made.
    Better HTML anchor names.

    0.11, 2000-09-20
    Sixth public review revision.
    Added ISO section reference numbers to most of the sections.

    0.10, 2000-07-30
    Sixth public review revision.

    0.09, 2000-02-17
    Fifth public review revision, still incomplete.

    0.08, 1999-10-31
    Fourth public review revision, still incomplete.
    Minor corrections made.
    Changed "C9X" to "C99" after the ratification of ISO C-1999.

    0.07, 1999-10-13
    Third public review revision, still incomplete.

    0.06, 1999-10-05
    Second public review revision, still incomplete.

    0.05, 1999-09-14
    First public review revision, still incomplete.

    0.00, 1999-08-24
    First attempt, incomplete.


    Copyright ©1999-2001 by David R. Tribble, all rights reserved.

    References and links to this document may be created without permission from the author. Portions of this document may be used or quoted without permission from the author provided that appropriate credit is given to the author. This document may be printed and distributed without permission from the author on the condition that the authorship and copyright notices remain present and unaltered.

    The author can be reached by email at david@tribble.com.
    The author's home web page is at david.tribble.com.