Definition of "Plain old Function" / "common subset of C++ and C languages" may be incorrect

85 views
Skip to first unread message

Johannes Schaub

unread,
Nov 17, 2016, 8:54:24 AM11/17/16
to std-dis...@isocpp.org
The spec says

"The common subset of the C and C++ languages consists of all
declarations, definitions, and expressions that may appear in a well
formed C++ program and also in a conforming C program."

However, that means that selected features of C++ such as overloading,
used by a C program which is accepted by a C compiler that treats
these features as conforming extensions, are among the "common
subset". That strikes me as incorrect, however. I think the spec
should instead say

"The common subset of the C and C++ languages consists of all
declarations, definitions, and expressions that may appear in a well
formed C++ program and also in a <ins>strictly</ins> conforming C
program."

Nicol Bolas

unread,
Nov 17, 2016, 10:24:13 AM11/17/16
to ISO C++ Standard - Discussion

I'm not sure that "strictly" is necessary here. If the C standard says that a program is il-formed if two declarations declare the same function with different parameters, then C code that uses such a thing is not conforming to the C standard. Whether a C compiler accepts it or not, the code doesn't conform to the standard.

Johannes Schaub

unread,
Nov 17, 2016, 10:57:35 AM11/17/16
to std-dis...@isocpp.org
The term has a strict, err precise, definition: "The two forms of
conforming implementation are hosted and freestanding. A conforming
hosted implementation shall accept any strictly conforming program" /
"A conforming program is one that is acceptable to a conforming
implementation.". Therefore, overloading functions is not a problem
for a conforming C program if a conforming C compiler accepts it.
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-discussio...@isocpp.org.
> To post to this group, send email to std-dis...@isocpp.org.
> Visit this group at
> https://groups.google.com/a/isocpp.org/group/std-discussion/.

Richard Smith

unread,
Nov 17, 2016, 1:06:09 PM11/17/16
to std-dis...@isocpp.org
On 17 Nov 2016 5:54 am, "'Johannes Schaub' via ISO C++ Standard - Discussion" <std-dis...@isocpp.org> wrote:
The spec says

  "The common subset of the C and C++ languages consists of all
declarations, definitions, and expressions that may appear in a well
formed C++ program and also in a conforming C program."

The committee is aware that this common subset approach doesn't work, and is in the process of removing and replacing this wording entirely. There are more significant issues than the one you present here (note that, for example, extern "C" declarations are not in the common subset, so immediately we can see that there are no valid signal handlers).

However, that means that selected features of C++ such as overloading,
used by a C program which is accepted by a C compiler that treats
these features as conforming extensions, are among the "common
subset". That strikes me as incorrect, however. I think the spec
should instead say

  "The common subset of the C and C++ languages consists of all
declarations, definitions, and expressions that may appear in a well
formed C++ program and also in a <ins>strictly</ins> conforming C
program."
--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+unsubscribe@isocpp.org.

Matthew Woehlke

unread,
Nov 18, 2016, 10:53:36 AM11/18/16
to std-dis...@isocpp.org
On 2016-11-17 10:57, 'Johannes Schaub' via ISO C++ Standard - Discussion
wrote:
> The term has a strict, err precise, definition: "The two forms of
> conforming implementation are hosted and freestanding. A conforming
> hosted implementation shall accept any strictly conforming program" /
> "A conforming program is one that is acceptable to a conforming
> implementation.". Therefore, overloading functions is not a problem
> for a conforming C program if a conforming C compiler accepts it.

I believe a more appropriate definition is that a conforming program is
one accepted by *all* conforming compilers. Moreover, both extant
conforming compilers and *hypothetical* conforming compilers.

Let's say I wrote a conforming "C" compiler that, as a permitted
extension, also accepted Python code. Does that mean that Python code is
part of conforming C? Certainly not. A conforming program is one that
*must* be accepted by the compiler in order for that compiler to be
conforming, i.e. any possible compiler which is conforming would
necessarily accept the program. Not *there exists* (or even, *might*
exist) a conforming compiler that would accept the program.

--
Matthew

T. C.

unread,
Nov 18, 2016, 12:19:34 PM11/18/16
to ISO C++ Standard - Discussion, mwoehlk...@gmail.com


On Friday, November 18, 2016 at 10:53:36 AM UTC-5, Matthew Woehlke wrote:
On 2016-11-17 10:57, 'Johannes Schaub' via ISO C++ Standard - Discussion
wrote:
> The term has a strict, err precise, definition: "The two forms of
> conforming implementation are hosted and freestanding. A conforming
> hosted implementation shall accept any strictly conforming program" /
> "A conforming program is one that is acceptable to a conforming
> implementation.". Therefore, overloading functions is not a problem
> for a conforming C program if a conforming C compiler accepts it.

I believe a more appropriate definition is that a conforming program is
one accepted by *all* conforming compilers. Moreover, both extant
conforming compilers and *hypothetical* conforming compilers. 

That abolishes all distinction between "conforming program" and "strictly conforming program".

Richard Smith

unread,
Nov 18, 2016, 8:18:43 PM11/18/16
to std-dis...@isocpp.org
On 17 November 2016 at 08:55, Matthew Woehlke <mwoehlk...@gmail.com> wrote:
On 2016-11-17 10:57, 'Johannes Schaub' via ISO C++ Standard - Discussion
wrote:
> The term has a strict, err precise, definition: "The two forms of
> conforming implementation are hosted and freestanding. A conforming
> hosted implementation shall accept any strictly conforming program" /
> "A conforming program is one that is acceptable to a conforming
> implementation.". Therefore, overloading functions is not a problem
> for a conforming C program if a conforming C compiler accepts it.

I believe a more appropriate definition is that a conforming program is
one accepted by *all* conforming compilers. Moreover, both extant
conforming compilers and *hypothetical* conforming compilers.

Let's say I wrote a conforming "C" compiler that, as a permitted
extension, also accepted Python code. Does that mean that Python code is
part of conforming C?

Well, there is no such thing as "conforming C". But yes, it would mean a Python program is a conforming program for *that* implementation (that is, it conforms to the rules of that implementation). The notion of a "conforming program" only really makes sense in the context of a particular implementation, which is another good reason why it's inappropriate for us to be using that term when defining a "Plain Old Function".

Certainly not. A conforming program is one that
*must* be accepted by the compiler in order for that compiler to be
conforming, i.e. any possible compiler which is conforming would
necessarily accept the program. Not *there exists* (or even, *might*
exist) a conforming compiler that would accept the program.

--
Matthew
--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+unsubscribe@isocpp.org.

Johannes Schaub

unread,
Nov 19, 2016, 5:13:05 PM11/19/16
to std-dis...@isocpp.org
The C rationale document has it spot on: "The three-fold definition of
compliance is used to broaden the population of conforming programs
and distinguish between conforming programs using a single
implementation and portable conforming programs.

A strictly conforming program is another term for a maximally portable
program. The goal is to give the programmer a fighting chance to make
powerful C programs that are also highly portable, without demeaning
perfectly useful C programs that happen not to be portable. Thus the
adverb strictly."
Reply all
Reply to author
Forward
0 new messages