Question about sequence points

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • spibou@gmail.com

    #1

    Question about sequence points

    Consider the expression x = f(...) ;

    1. The function f may or may not take arguments.
    x is a global variable which is visible to f and any
    functions which may be called by f or functions
    which appear as arguments to f in the above
    expression.

    2. The list of arguments to f does not contain any
    operators which modify the value of x and also
    functions called by f or appearing as arguments to
    f do not modify the value of x.

    3. f itself may modify the value of x.

    Is the above expression well defined ? If you think
    it is could you explain how it follows from the standard ?

    Personally I feel it is well defined. If there are any disagreements
    I will explain my reasoning later.


    Spiros Bousbouras

  • Eric Sosman

    #2
    Re: Question about sequence points



    spibou@gmail.co m wrote On 08/04/06 08:53,:
    Consider the expression x = f(...) ;
    >
    1. The function f may or may not take arguments.
    x is a global variable which is visible to f and any
    functions which may be called by f or functions
    which appear as arguments to f in the above
    expression.
    >
    2. The list of arguments to f does not contain any
    operators which modify the value of x and also
    functions called by f or appearing as arguments to
    f do not modify the value of x.
    >
    3. f itself may modify the value of x.
    >
    Is the above expression well defined ? If you think
    it is could you explain how it follows from the standard ?
    >
    Personally I feel it is well defined. If there are any disagreements
    I will explain my reasoning later.
    Well-defined. There is a sequence point after the
    arguments are evaluated, before the body of f() begins
    executing. If f() is written in C, there is another
    sequence point at the end of each of its statements; in
    particular, there is a sequence point at the end of the
    `return somevalue;' statement. (If f() is not written
    in C, all bets are off: The C Standard does not govern
    what other languages do.)

    --
    Eric.Sosman@sun .com

    Comment

    • Chris F.A. Johnson

      #3
      Re: Question about sequence points

      On 2006-08-04, Eric Sosman wrote:
      >
      spibou@gmail.co m wrote On 08/04/06 08:53,:
      >
      >Personally I feel it is well defined. If there are any disagreements
      >I will explain my reasoning later.
      >
      Well-defined.
      <OT>
      No, "well defined" is correct unless it precedes the noun, as in
      "well-defined function".
      </OT>

      --
      Chris F.A. Johnson, author | <http://cfaj.freeshell. org>
      Shell Scripting Recipes: | My code in this post, if any,
      A Problem-Solution Approach | is released under the
      2005, Apress | GNU General Public Licence

      Comment

      • Clark S. Cox III

        #4
        Re: Question about sequence points

        On 2006-08-04 08:53:15 -0400, spibou@gmail.co m said:
        Consider the expression x = f(...) ;
        >
        1. The function f may or may not take arguments.
        x is a global variable which is visible to f and any
        functions which may be called by f or functions
        which appear as arguments to f in the above
        expression.
        >
        2. The list of arguments to f does not contain any
        operators which modify the value of x and also
        functions called by f or appearing as arguments to
        f do not modify the value of x.
        >
        3. f itself may modify the value of x.
        >
        Is the above expression well defined ? If you think
        it is could you explain how it follows from the standard ?
        >
        Personally I feel it is well defined. If there are any disagreements
        I will explain my reasoning later.
        Why wouldn't it be well defined?

        int x;

        int f(int,int,int)
        {
        return x++;//There is a sequence point at the end of this expression
        }

        int main()
        {
        x = f(1,2,3); //There is a sequence point at the call itself

        //x == 0 at this point


        return 0;
        }

        --
        Clark S. Cox, III
        clarkcox3@gmail .com

        Comment

        Working...