Topic: Implementation-defined behavior: Is complex logic allowed to defin= e it?
Author: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Date: Thu, 22 Jul 2010 12:35:01 CST Raw View
I'm wondering about what implementation defined behavior is, in and of
itself. The Standard says:
"
Certain aspects and operations of the abstract machine are described in thi=
s
International Standard as implementation-defined (for example, sizeof(int))=
These constitute the parameters of the abstract machine. Each implementatio=
n
shall include documentation describing its characteristics and behavior in
these respects. Such documentation shall define the instance of the abstrac=
t
machine that corresponds to that implementation (referred to as the
=91=91corresponding instance=92=92 below).
"
Let's take the statement "A multicharacter literal has type int and
implementation-defined value.". Is a valid implementation-defined behavior
to say the following?
"If the character literal appears within a constant-expression, its value i=
s
X. Otherwise, its value is Y".
This is completely deterministic. But it yields different values for
differerent appearances of the character literal for the same corresponding
abstract machine and same input. Is that kosher?
Any insights? Thanks!
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: =3D?ISO-8859-1?Q?Daniel_Kr=3DFCgler?=3D <daniel.kruegler@googlemail.c=.om>
Date: Fri, 23 Jul 2010 13:03:09 CST Raw View
On 22 Jul., 20:35, "Johannes Schaub (litb)" <schaub-johan...@web.de>
wrote:
> I'm wondering about what implementation defined behavior is, in and of
> itself. The Standard says:
>
> "
> Certain aspects and operations of the abstract machine are described in
thi=
> s
> International Standard as implementation-defined (for example,
sizeof(int))=
> These constitute the parameters of the abstract machine. Each
implementatio=
> n
> shall include documentation describing its characteristics and behavior i=
n
> these respects. Such documentation shall define the instance of the
abstrac=
> t
> machine that corresponds to that implementation (referred to as the
> =91=91corresponding instance=92=92 below).
> "
>
> Let's take the statement "A multicharacter literal has type int and
> implementation-defined value.". Is a valid implementation-defined behavio=
r
> to say the following?
>
> "If the character literal appears within a constant-expression, its value
i=
> s
> X. Otherwise, its value is Y".
Here I have to check, who is saying this: Is this one possible example
for an implementation documentation or are you referring to some
other normative part of the standard (which I couldn't find in the
FCD)?
> This is completely deterministic. But it yields different values for
> differerent appearances of the character literal for the same
corresponding
> abstract machine and same input. Is that kosher?
>
> Any insights? Thanks!
I'm not sure, that I correctly understand your question. In
fact, I have the impression, that you are asking two
different questions ;-)
1) I assume, you are asking whether an implementation
documentation may satisfy the requirement to document
the implementation-defined values of multicharacter literals
in way of:
"If the character literal appears within a constant-expression,
its value is X. Otherwise, its value is Y"
Notwithstanding the symbolic character of this description
the standard does not require a special form of the
implementation documentation. I assume that above
description is complete. Assuming all this, there is
no reason why above statement should not be a valid
documentation as required by the standard.
2) The second and probably more interesting question
is, whether above documentation has implications
which would violate *other* parts of the standard. But
this question is completely independent on the decision
whether the quoted statement satisfies the requirements
of documentation of implementation-defined things.
If we check (all quotes are relative to FCD) 16.1/4
which discusses a special set of /constant-expressions/
occurring in preprocessing tokens, we find the following:
"[..] For the purposes of this token conversion and
evaluation all signed and unsigned integer types act
as if they have the same representation as, respectively,
intmax_t or uintmax_t (18.4).147 This includes interpreting
character literals, which may involve converting escape
sequences into execution character set members.
Whether the numeric value for these character literals
matches the value obtained when an identical character
literal occurs in an expression (other than within a #if or
#elif directive) is implementation-defined. (footnote 148)"
with footnote 148:
"148) Thus, the constant expression in the following #if
directive and if statement is not guaranteed to evaluate
to the same value in these two contexts.
#if =92z=92 - =92a=92 == 25
if (=92z=92 - =92a=92 == 25)
"
Further-on, the standard is intentionally pretty silent,
*when* constant-expressions are evaluated. The idea
is to allow a cross-compiler to evaluate all constant
expressions with a potentially different bitsize (e.g.
8-bit char) as the actual target compiler that might be
running on a different architecture (e.g. 9-bit char).
This affects especially the evaluation of constant
expressions involving floating-point values, but as
above example shows there is also some latitude
given for character types. So I think - but I'm not
100% sure - that above form also is in agreement
with the remaining requirements of the language.
HTH & Greetings from Bremen,
Daniel Kr=FCgler
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: James Kanze <james.kanze@gmail.com>
Date: Fri, 23 Jul 2010 13:18:26 CST Raw View
On Jul 22, 7:35 pm, "Johannes Schaub (litb)" <schaub-johan...@web.de>
wrote:
> I'm wondering about what implementation defined behavior is,
> in and of itself. The Standard says:
> "
> Certain aspects and operations of the abstract machine are
> described in thi= s International Standard as
> implementation-defined (for example, sizeof(int))= These
> constitute the parameters of the abstract machine. Each
> implementatio= n shall include documentation describing its
> characteristics and behavior in these respects. Such
> documentation shall define the instance of the abstrac=
> t machine that corresponds to that implementation (referred to
> as the =91=91corresponding instance=92=92 below).
> "
> Let's take the statement "A multicharacter literal has type
> int and implementation-defined value.". Is a valid
> implementation-defined behavior to say the following?
> "If the character literal appears within
> a constant-expression, its value i= s X. Otherwise, its value
> is Y".
I'm not sure about the validity of your example. A character
literal *is* a constant expression. But in general, a compiler
can specify implementation defined behavior in more or less
complex ways.
--
James Kanze
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Francis Glassborow <francis.glassborow@btinternet.com>
Date: Fri, 23 Jul 2010 13:18:27 CST Raw View
Johannes Schaub (litb) wrote:
> I'm wondering about what implementation defined behavior is, in and of
> itself. The Standard says:
>
> "
> Certain aspects and operations of the abstract machine are described in
> thi=
> s
> International Standard as implementation-defined (for example,
> sizeof(int))=
> These constitute the parameters of the abstract machine. Each
> implementatio=
> n
> shall include documentation describing its characteristics and behavior in
> these respects. Such documentation shall define the instance of the
> abstrac=
> t
> machine that corresponds to that implementation (referred to as the
> =91=91corresponding instance=92=92 below).
> "
>
> Let's take the statement "A multicharacter literal has type int and
> implementation-defined value.". Is a valid implementation-defined behavior
> to say the following?
>
> "If the character literal appears within a constant-expression, its value
> i=
> s
> X. Otherwise, its value is Y".
>
> This is completely deterministic. But it yields different values for
> differerent appearances of the character literal for the same corresponding
> abstract machine and same input. Is that kosher?
>
> Any insights? Thanks!
>
> AIUI an implementation is allowed to define behaviour in reference to the
phases of the moon. Clearly no implementation is going to do such a thing if
it expects to be taken seriously nut nonetheless as long as the value is
defined it meets the requirements of the standard.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]