sequence points and the execution model

Discussion in 'C Programming' started by George, Jan 17, 2009.

  1. George

    George Guest

    I'm given to understand that determining order has to do with the execution
    model in C.

    May a C program read its own source?
    --
    larry

    We question most of the mantras around here periodically, in case
    you hadn't noticed. :)
    -- Larry Wall in <>
    George, Jan 17, 2009
    #1
    1. Advertising

  2. George

    James Kuyper Guest

    George wrote:
    >
    > I'm given to understand that determining order has to do with the execution
    > model in C.


    Determining the order of what? If you're referring to the order of
    evaluation of expressions, that statement is both true and relevant to
    subject line, but it's so vague as to be pointless. What was your
    purpose in making it?

    > May a C program read its own source?


    Of course; it's a file like any other, and therefore can be opened by
    any C program that's written to read a file, so long as you make that
    file available to the program.

    I'm curious - do you see any connection between this question, your
    previous comment, and the Subject: header for this message? I don't.
    James Kuyper, Jan 17, 2009
    #2
    1. Advertising

  3. Mark McIntyre wrote:
    > The order of execution of statements is defined by the Standard. To a
    > large extent it depends on the presence of sequence points. The location
    > of these is defined by the language standard. Where multiple statements
    > occur between two given sequence points, their order of execution /may/
    > be defined by other sections of the standard - but if not, then the
    > order of execution is undefined. I believe a simple example of that
    > would be a comma-separated list of assignments.


    Doesn't the comma operator create a sequence point, just like a semicolon?

    S

    --
    Stephen Sprunk "Stupid people surround themselves with smart
    CCIE #3723 people. Smart people surround themselves with
    K5SSS smart people who disagree with them." --Isaac Jaffe
    Stephen Sprunk, Jan 17, 2009
    #3
  4. Stephen Sprunk <> writes:

    > Mark McIntyre wrote:
    >> The order of execution of statements is defined by the Standard. To
    >> a large extent it depends on the presence of sequence points. The
    >> location of these is defined by the language standard. Where
    >> multiple statements occur between two given sequence points, their
    >> order of execution /may/ be defined by other sections of the
    >> standard - but if not, then the order of execution is undefined. I
    >> believe a simple example of that would be a comma-separated list of
    >> assignments.

    >
    > Doesn't the comma operator create a sequence point, just like a
    > semicolon?


    Yes, and I think it is stretching the terminology to say "where
    multiple statements occur between two given sequence points" since
    there is a sequence point at the end of every statement.

    Of course, you can have a "comma-separated list of assignments" with
    no comma operator: f(a=1, b=2, c=3);.

    --
    Ben.
    Ben Bacarisse, Jan 17, 2009
    #4
  5. Mark McIntyre wrote:
    > Ben Bacarisse wrote:
    >> Of course, you can have a "comma-separated list of assignments" with
    >> no comma operator: f(a=1, b=2, c=3);.


    Ah! I didn't think of that case, since I'd never put an assignment
    inside an argument list.

    > quite. I suspect that
    >
    > int a,b,c;
    > a=1,b=2,c=3;
    >
    > also counts?


    No. There, you are using the comma operator, so there are sequence
    points between the assignments. The comma in an argument list, however,
    is not the comma operator and thus does not create a sequence point.

    S

    --
    Stephen Sprunk "Stupid people surround themselves with smart
    CCIE #3723 people. Smart people surround themselves with
    K5SSS smart people who disagree with them." --Isaac Jaffe
    Stephen Sprunk, Jan 19, 2009
    #5
  6. Mark McIntyre <> writes:

    > Ben Bacarisse wrote:
    >> Stephen Sprunk <> writes:
    >>
    >>> Mark McIntyre wrote:
    >>>> The order of execution of statements is defined by the Standard. To
    >>>> a large extent it depends on the presence of sequence points. The
    >>>> location of these is defined by the language standard. Where
    >>>> multiple statements occur between two given sequence points, their
    >>>> order of execution /may/ be defined by other sections of the
    >>>> standard - but if not, then the order of execution is undefined. I
    >>>> believe a simple example of that would be a comma-separated list of
    >>>> assignments.
    >>> Doesn't the comma operator create a sequence point, just like a
    >>> semicolon?

    >
    > It does, but I wasn't referring to the coma operator...


    But you do below. I think you need to say exactly what mean.

    >> Yes, and I think it is stretching the terminology to say "where
    >> multiple statements occur between two given sequence points" since
    >> there is a sequence point at the end of every statement.

    >
    > I'm not so sure that's stretching the terminology.


    I can't think of how multiple statements can occur between two
    sequence points. I thought you were being lax using the term
    "statement", but there must be some explanation. Can you give an
    example so we call see what you mean?

    >> Of course, you can have a "comma-separated list of assignments" with
    >> no comma operator: f(a=1, b=2, c=3);.

    >
    > quite.


    Yes, but it is not an example of the first point since it is only one
    statement.

    > I suspect that
    >
    > int a,b,c;
    > a=1,b=2,c=3;
    >
    >
    > also counts?


    It is certainly a comma-separated list of assignments, but it does use
    the comma operator, has three sequence points (one at the end), and is
    a single statement.

    --
    Ben.
    Ben Bacarisse, Jan 19, 2009
    #6
  7. George

    James Kuyper Guest

    Mark McIntyre wrote:
    > Ben Bacarisse wrote:
    >> Stephen Sprunk <> writes:
    >>
    >>> Mark McIntyre wrote:
    >>>> The order of execution of statements is defined by the Standard. To
    >>>> a large extent it depends on the presence of sequence points. The
    >>>> location of these is defined by the language standard. Where
    >>>> multiple statements occur between two given sequence points, their
    >>>> order of execution /may/ be defined by other sections of the
    >>>> standard - but if not, then the order of execution is undefined. I
    >>>> believe a simple example of that would be a comma-separated list of
    >>>> assignments.
    >>> Doesn't the comma operator create a sequence point, just like a
    >>> semicolon?

    >
    > It does, but I wasn't referring to the coma operator...
    >
    >> Yes, and I think it is stretching the terminology to say "where
    >> multiple statements occur between two given sequence points" since
    >> there is a sequence point at the end of every statement.

    >
    > I'm not so sure that's stretching the terminology.


    Multiple statements never occur between two given sequence points,
    because every statement is separated from any preceding or following
    statements by a sequence point. I presume that what you were actually
    referring to was "where multiple expressions occur between two sequence
    points".

    >> Of course, you can have a "comma-separated list of assignments" with
    >> no comma operator: f(a=1, b=2, c=3);.

    >
    > quite. I suspect that
    >
    > int a,b,c;
    > a=1,b=2,c=3;
    >
    >
    > also counts?


    No, in that case the ',' character does serve as a comma operator.
    James Kuyper, Jan 19, 2009
    #7
  8. George

    Richard Guest

    Mark McIntyre <> writes:

    > James Kuyper wrote:
    >
    >> Multiple statements never occur between two given sequence points,
    >> because every statement is separated from any preceding or following
    >> statements by a sequence point. I presume that what you were
    >> actually referring to was "where multiple expressions occur between
    >> two sequence points".

    >
    > It was - I should have been more c-standards compliant in my language. :)
    >
    >>> a=1,b=2,c=3;
    >>>
    >>> also counts?

    >>
    >> No, in that case the ',' character does serve as a comma operator.

    >
    > Which all just goes to show how interesting this topic can become!


    "quite".
    Richard, Jan 20, 2009
    #8
    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. John Smith

    sequence points and evaluation order

    John Smith, Sep 4, 2006, in forum: C Programming
    Replies:
    9
    Views:
    347
    Robert Gamble
    Sep 6, 2006
  2. Divick
    Replies:
    2
    Views:
    320
    Divick
    Sep 5, 2006
  3. Dave Rahardja
    Replies:
    8
    Views:
    405
    Dave Rahardja
    Jul 5, 2007
  4. Kaz Kylheku

    Re: sequence points and the execution model

    Kaz Kylheku, Jan 18, 2009, in forum: C Programming
    Replies:
    5
    Views:
    308
    Phil Carmody
    Jan 20, 2009
  5. Larry Gates

    Re: sequence points and the execution model

    Larry Gates, Jan 19, 2009, in forum: C Programming
    Replies:
    59
    Views:
    1,113
    Tim Rentsch
    Feb 12, 2009
Loading...

Share This Page