Like Tree4Likes
  • 4 Post By laserlight

In C terminology, whats a 'sequence point.'

This is a discussion on In C terminology, whats a 'sequence point.' within the C Programming forums, part of the General Programming Boards category; A programmer in our community thought he found a compiler bug while using vbcc on a motorola 68000. vbcc ANSI/ISO-C ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Location
    Beaverton, Oregon, United States
    Posts
    158

    In C terminology, whats a 'sequence point.'

    A programmer in our community thought he found a compiler bug while using vbcc on a motorola 68000.

    vbcc ANSI/ISO-C compiler

    Anyways, this was the compiler error he thought he found.


    Quote Originally Posted by VladR View Post
    I just found out another compiler bug (related to postincrementing) after spending few hrs trying to "debug" using just the text output through the VirtualJaguar.

    This:
    Code:
    DbgStr.Lines [DbgStr.LinesCount].Line [i] = msg [i++];
    had to be changed into this, otherwise it was offset by 1:
    Code:
    DbgStr.Lines [DbgStr.LinesCount].Line [i] = msg [i];
      i++;

    Pretty nasty. I wonder how many of those bugs will I enncounter...
    Anyway I shot this finding off to Dr Volker along with the other bug referenced, which still has not been ironed out yet, and this was his reply to the above mentioned bug in this line:

    Code:
    DbgStr.Lines [DbgStr.LinesCount].Line [i] = msg [i++];
    Quote Originally Posted by Volker
    This is illegal C code, because you are reading and writing in between sequence points.
    So while another real experienced coder has some issues with the above line, everyone is scratching their head about what a 'sequence point' is.

    I probably didnt have to go so in depth but figured needed a context.
    Last edited by A34Chris; 11-19-2012 at 07:56 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,414
    Your Dr Volker is indeed correct.

    This is what the C standard states:
    Quote Originally Posted by C99 Clause 5.1.2.3 Paragraph 2
    Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects, which are changes in the state of the execution environment. Evaluation of an expression may produce side effects. At certain specified points in the execution sequence called sequence points, all side effects of previous evaluations shall be complete and no side effects of subsequent evaluations shall have taken place. (A summary of the sequence points is given in annex C.)
    Quote Originally Posted by C99 Clause 6.5 Paragraph 2
    Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.
    Quote Originally Posted by C99 Annex C
    The following are the sequence points described in 5.1.2.3:
    — The call to a function, after the arguments have been evaluated (6.5.2.2).
    — The end of the first operand of the following operators: logical AND && (6.5.13); logical OR || (6.5.14); conditional ? (6.5.15); comma , (6.5.17).
    — The end of a full declarator: declarators (6.7.5);
    — The end of a full expression: an initializer (6.7.8); the expression in an expression statement (6.8.3); the controlling expression of a selection statement (if or switch) (6.8.4); the controlling expression of a while or do statement (6.8.5); each of the expressions of a for statement (6.8.5.3); the expression in a return statement (6.8.6.4).
    — Immediately before a library function returns (7.1.4).
    — After the actions associated with each formatted input/output function conversion specifier (7.19.6, 7.24.2).
    — Immediately before and immediately after each call to a comparison function, and also between any call to a comparison function and any movement of the objects passed as arguments to that call (7.20.5).
    Notice that there is no sequence point introduced by the assignment operator= hence that line has a bug. It is not a bug with the compiler.
    Last edited by laserlight; 11-19-2012 at 08:02 PM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2006
    Location
    Beaverton, Oregon, United States
    Posts
    158
    Thank you very much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Terminology
    By r_james14 in forum C Programming
    Replies: 4
    Last Post: 11-24-2011, 08:37 AM
  2. Template metaprogramming, whats the point?
    By Cogman in forum C++ Programming
    Replies: 26
    Last Post: 02-01-2009, 10:47 PM
  3. Whats the point of pointers?
    By Goosie in forum C++ Programming
    Replies: 22
    Last Post: 06-22-2005, 05:38 PM
  4. Whats the point of const?
    By Grins2Pain in forum C++ Programming
    Replies: 15
    Last Post: 09-30-2003, 04:53 PM
  5. join and dont post - whats the point
    By iain in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 01-28-2002, 05:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21