More about behaviour

J

Joona I Palaste

Let's look at it this way. I provide examples of all four classes of
behaviour and their allowed outcomes.

1) Defined behaviour:
Expression: 1
Allowed values: 1

2) Implementation-defined behaviour:
Expression: sizeof(int)
Allowed values: Any positive integer. The value must remain the same on
each evaluation of the expression, and must be documented.

3) Unspecified behaviour:
Sample code:
int foo(void) {
static int x=0;
return x++;
}
Expression: 2*foo()+foo()
Allowed values: 1 or 2. The value need not remain the same on each
evaluation of the expression.

4) Undefined behaviour:
Expression: *((int *)0)
Allowed values: Anything.

Now, if I'm correct here, the implementation is free to "act as if"
the C standard mandated that the expression in (2) must have the value
of 2.
It is also free to "act as if" the C standard mandated that the
expression in (3) can have either the value of 1 or the value of 2,
but it must always remain the same.
It is also free to "act as if" the C standard mandated that the
expression in (4) can have any positive integer value, which the
implementation can pick out of the blue, and need not be consistent
(but it must always be a positive integer).

If I'm correct here then my theory about ordering the classes of
behaviour should be valid.

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Shh! The maestro is decomposing!"
- Gary Larson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top