Topic: Standard and reference implementation (Was: Is C++


Author: "Sergey P. Derevyago" <non-existent@iobox.com>
Date: Tue, 9 Oct 2001 09:34:56 GMT
Raw View
Martin von Loewis wrote:
> > I'm not sure I understand what you mean. Could you give me an example
> > that did not involve undefined behaviour?
>
> Certainly.
>
> #include <stdio.h>
>
> int main()
> {
>   printf("%d\n", sizeof(int));
> }
>
> does not does not involve undefined behaviour;
 Unfortunately, it (clearly?) does involve undefined behavior: sizeof()
returns size_t which is NOT int.
--
         With all respect, Sergey.          http://cpp3.virtualave.net/
         mailto : ders at skeptik.net

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "James Russell Kuyper Jr." <kuyper@wizard.net>
Date: Tue, 9 Oct 2001 18:03:25 GMT
Raw View
"Sergey P. Derevyago" wrote:
>
> Martin von Loewis wrote:
> > > I'm not sure I understand what you mean. Could you give me an example
> > > that did not involve undefined behaviour?
> >
> > Certainly.
> >
> > #include <stdio.h>
> >
> > int main()
> > {
> >   printf("%d\n", sizeof(int));
> > }
> >
> > does not does not involve undefined behaviour;
>         Unfortunately, it (clearly?) does involve undefined behavior: sizeof()
> returns size_t which is NOT int.

Easily fixed:

 printf("%lu\n", (unsigned long)sizeof(int));

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Nicola Musatti <objectway@divalsim.it>
Date: Tue, 9 Oct 2001 18:02:58 GMT
Raw View
Martin von Loewis wrote:
>
> Nicola Musatti <objectway@divalsim.it> writes:
>
> > Valentin Bonnard wrote:
> > [...]
> > > C++, as all non deterministic languages (read: all modern
> > > real-world languages, defines an infinite set of possible
> > > behaviors for a given C++ program. This set is even more
> > > infinite than in safe languages, because it includes the
> > > possibility of undefined behavior.
> >
> > I'm not sure I understand what you mean. Could you give me an example
> > that did not involve undefined behaviour?
>
> Certainly.
>
> #include <stdio.h>
>
> int main()
> {
>   printf("%d\n", sizeof(int));
> }
>
> does not does not involve undefined behaviour; this program must print
> a number on each conforming implementation. Which number it prints
> exactly is implementation-defined. Likewise, what exactly std::stdout
> is that I use in this example is implementation-defined: it could be a
> line printer, or a CDE terminal window.

Okay. For each valid program there is a set of equally valid possible
behaviours, yet all implementations must agree on whether it is a valid
program or not.

[...]
> It is not possible to construct a test suite that reliably determines
> whether an implementation conforms to C++.
>
> IOW, for any test suite you construct, I can create a compiler that
> passes your all your tests, but still is not conforming. That compiler
> is very easy to construct:
>
>   For any given program, determine whether it is part of the test
>   suite. If so, generate an executable that produces the expected
>   output. For any other input program, generate an executable that
>   prints "Hello, World!".

You assume that it is possible to write correct programs that are not
recognizable by my test suite: can you prove that?

Yours and Valentin's argument remind me of the halting problem: while in
general you can't prove that an arbitrary program terminates, we know
techniques that let us write programs that can be proved to terminate.

Maybe it is possible to design a language (and to write its
specification) in a way that allows proof of conformance. Otherwise I
wonder what do Ada people think they achieved...

I realize that C++ was not designed with proof of conformance in mind
and that it might be impossible to design a complete verification test
for this language.

[...]
> > You can use the reference implementation to complement your commercial
> > one with an initial version of features you hadn't implemented yet.
>
> That certainly depends on the licensing of the "reference
> implementation". In fact, what you are asking is a "relicensable
> implementation". There are several such implementations of C++
> available: on the "core" side, you can get licenses for EDG, g++, and
> others; for the library, you can get licenses from RogueWave,
> Dinkumware, and others. There is no need to declare any of them as a
> "reference implementation" - companies already license these
> implementations to incorporate them into their products.

While these organizations have their merits, their impact is not as deep
as a freely available implementation might have. On the other hand the
advantage of a reference implementation is probably bigger when it is
also the first implementation available, thus providing a level ground
for competitors. This certainly not the case with C++ implementors.

Cheers,
Nicola Musatti

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "James Russell Kuyper Jr." <kuyper@wizard.net>
Date: Wed, 10 Oct 2001 08:15:47 GMT
Raw View
Nicola Musatti wrote:
>
> Martin von Loewis wrote:
> >
> > Nicola Musatti <objectway@divalsim.it> writes:
> >
> > > Valentin Bonnard wrote:

...
> Okay. For each valid program there is a set of equally valid possible
> behaviours, yet all implementations must agree on whether it is a valid
> program or not.

Not true. Whether or not a program is valid can depend upon
implementation-specific characteristics, so different implementations
will necessarily disagree about whether it is valid:

int main()
{
 int[sizeof(int)-3];

 return 0;
}

> [...]
> > It is not possible to construct a test suite that reliably determines
> > whether an implementation conforms to C++.
> >
> > IOW, for any test suite you construct, I can create a compiler that
> > passes your all your tests, but still is not conforming. That compiler
> > is very easy to construct:
> >
> >   For any given program, determine whether it is part of the test
> >   suite. If so, generate an executable that produces the expected
> >   output. For any other input program, generate an executable that
> >   prints "Hello, World!".
>
> You assume that it is possible to write correct programs that are not
> recognizable by my test suite: can you prove that?

Your test suite recognizes programs? I thought it tested
implementations?

What he said was that it's possible for him to write an incorrect
implementation of C++ that will pass your test suite. He's right, too;
and what he's already said is all the proof needed. He's described
precisely how, given any particular test suite, to construct such an
implementation.

The fundamental problem is that the C++ standard says something about
how a conforming implementation should process an extremely large number
of different programs. This includes not only all strictly conforming
programs, but also all programs for which a diagnostic is mandatory. An
implementation is incorrect if it processes any one of those programs
incorrectly, even if it processes every other program correctly.
Therefore, the only test suite that can verify conformance is the
complete collection of all such programs.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: "James Russell Kuyper Jr." <kuyper@wizard.net>
Date: Wed, 10 Oct 2001 17:21:50 GMT
Raw View
"James Russell Kuyper Jr." wrote:
...
> Not true. Whether or not a program is valid can depend upon
> implementation-specific characteristics, so different implementations
> will necessarily disagree about whether it is valid:
>
> int main()
> {
>         int[sizeof(int)-3];

Correction:

 int array[sizeof(int)-3];

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Nicola Musatti <objectway@divalsim.it>
Date: Wed, 10 Oct 2001 18:23:39 GMT
Raw View

"James Russell Kuyper Jr." wrote:
[...]
> The fundamental problem is that the C++ standard says something about
> how a conforming implementation should process an extremely large number
> of different programs. This includes not only all strictly conforming
> programs, but also all programs for which a diagnostic is mandatory. An
> implementation is incorrect if it processes any one of those programs
> incorrectly, even if it processes every other program correctly.
> Therefore, the only test suite that can verify conformance is the
> complete collection of all such programs.

I still wonder though why can an Ada implementation be certified for
compliancy to the Ada standard and the same should not be possible for
C++? Are the Ada people just deluding themselves or is there a
difference?

Cheers,
Nicola Musatti

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]





Author: Nicola Musatti <objectway@divalsim.it>
Date: Mon, 8 Oct 2001 19:02:43 GMT
Raw View
Hallo, Valentin.
my suggestion about a reference implementation for C++ stemmed directly
from Richard Riehle's description of how something similar exists for
Ada.

Personally I find that approach feasible, where by "feasible" I mean
that it could produce concrete results, not that there's people
available to put in the effort to produce those results.

To recap the Ada standardization committee produced a validation test
suite that practically defines how a compliant compiler should behave
and a reference compiler which is compliant according to the test suite.
Wouldn't it be possible to pursue the same route for C++?

Valentin Bonnard wrote:
[...]
> C++, as all non deterministic languages (read: all modern
> real-world languages, defines an infinite set of possible
> behaviors for a given C++ program. This set is even more
> infinite than in safe languages, because it includes the
> possibility of undefined behavior.

I'm not sure I understand what you mean. Could you give me an example
that did not involve undefined behaviour?

> So an implementation is really a choice among the infinite
> set of allowed behaviors. (Actually, if the implementation
> is non-deterministic, as all are, it is a choice of an
> infinite subset of the set of allowed behavior (power-set
> operation).)
>
> In short: standards (specifications) and compilers
> (implementations) don't live in the same world.
>
> But let's say you have an implementation of the standard.
>
> (Note: how do you know you have an implementation of C++ ?
> You don't. You just assume you have one. Until you have a
> problem -- I won't enter this issue.)

The idea is to have a set of tests that let you check the conformance of
an implementation.

> What can you do with that implementation ? Obviously you
> are going to write demos. Then you compile the demos. But
> ill-formed program can compile fine on conforming compilers
> (ODR violations, invalid redefinitions of members, non-
> functionaly equivalent template definitions...). Then you
> run your demo. Incorrect code (whatever it means) can run
> just fine when compiled with a conforming compiler.

You can use the reference implementation to complement your commercial
one with an initial version of features you hadn't implemented yet. For
instance most commercial versions of the X Window System started out as
little more than the original reference implementation provided by MIT.

Cheers,
Nicola Musatti

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]