More about behaviour

Discussion in 'C Programming' started by Joona I Palaste, Aug 18, 2003.

  1. 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 () ---------------------------\
    | 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
     
    Joona I Palaste, Aug 18, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Trebilcock

    More Strange Server Behaviour

    Mike Trebilcock, Sep 22, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    366
    Mike Trebilcock
    Sep 22, 2005
  2. Re: Still more about behaviour

    , Aug 22, 2003, in forum: C Programming
    Replies:
    3
    Views:
    287
    Jun Woong
    Aug 24, 2003
  3. Michael
    Replies:
    4
    Views:
    472
    Matt Hammond
    Jun 26, 2006
  4. Andy Chambers
    Replies:
    1
    Views:
    411
    Daniel Dyer
    May 14, 2007
  5. Robert Klemme

    With a Ruby Yell: more, more more!

    Robert Klemme, Sep 28, 2005, in forum: Ruby
    Replies:
    5
    Views:
    241
    Jeff Wood
    Sep 29, 2005
Loading...

Share This Page