4

The C++11 standard makes a couple of passing mentions to "function prototypes".

There are not in any definitions of the relevant features, but in random places like:

  • "function prototype scope" in [C++11: 3.3.4] (whose definition actually admits it's talking about "function declarations");
  • an editorial description of the library type definition clauses in [C++11: 17.5.1.4/1], footnote 175 (which seems to be referring to the C functionality);
  • [C++11: 20.9.4.3/6] which describes the hypothetical template <T> typename add_rvalue_reference<T>::type create(); as "a function prototype".
  • the same thing at [C++11: 20.9.6/4];
  • appendix [C++11: C.1.7] which talks about declarators in C: "The function declarations using C incomplete declaration style must be completed to become full prototype declarations, then later "Rationale: Prototypes are essential to type safety".

... and that's it.

Surely, we are set on the "declaration"/"definition" terminology and, since the C++ standard does not use the "prototype" terminology in its core definitions, these are merely typos/inconsistencies, introduced because some editors are familiar with C terminology?

Or is there some subtle meaning I'm missing?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • 3
    How are C prototypes "something quite different"? In C, a prototype is a function declaration that specifies the type(s) of the parameters. In C++, all function declarations do so. – Keith Thompson Jan 04 '14 at 02:40
  • @Keith: C prototypes support *identifier-list*s and all sorts of weird magic, including omitting parameters entirely (or is that declarations without prototypes?). If nothing else, the _C++_ standard calls them function declarations, so it's strange to have this small handful of passing references to different terminology. – Lightness Races in Orbit Jan 04 '14 at 02:44
  • @Lightness I think you have that [backwards](http://stackoverflow.com/a/5481685/241631). Sorry, too lazy to find something more normative than JerryCoffin :) – Praetorian Jan 04 '14 at 02:45
  • @Praetorian: Okay, you're right! I shall edit accordingly. It's only a small and insubstantial change to the question. – Lightness Races in Orbit Jan 04 '14 at 02:46
  • 6
    @Lightness The answer probably is *the committee members are not as anal retentive as you are* :P – Praetorian Jan 04 '14 at 02:57
  • 2
    @Praetorian: Something more normative: [N1570](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf) 6.2.1p2: "A *function prototype* is a declaration of a function that declares the types of its parameters." – Keith Thompson Jan 04 '14 at 03:37

1 Answers1

4

Yes and no. I think some of the uses of "prototype" make sense, but others should really be changed to "declaration".

  • I agree that §3.3.4/1 should talk about "function declaration scope" instead of "function prototype scope".
  • §17.5.1.4 is talking about C++ headers, so I think it should probably use "declaration" instead of prototype.
  • Footnote 175 is specifically referring to what is provided by C headers, so there I think it's probably appropriate to use C terminology (i.e., to continue to use "prototype", though possibly with an added note that this is equivalent to a C++ declaration).
  • I'd agree that the use of "prototype" at §20.9.6/4 and §20.9.4.3/6 are both mistakes, and should use "declaration" instead.
  • C.1.7 is specifically comparing C to C++, talking about declarations vs. prototypes in C and how they compare to C++ declarations, so it nearly needs to retain the use of "prototype" to be meaningful.

As to a definition of "prototype" (or related features), ISO 9899:1999 (through TC 3) is a normative reference to the C++ standard, so its definition of "prototype" can be applied since the C++ standard itself provides none.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111