Sunday, June 1, 2008

What's the concept of Sequence Point in C?


Question: What's the concept of Sequence Point in C?

Answer: It's a point in time during the execution where all the side effects of the execution are guaranteed to be complete. As per ANSI/ISO C Standard " 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 accessed only to determine the value to be stored". This means that if an object is being modified within two sequence points, then all the accesses to that variable must be for the purpose of computing the modified value only. This is the reasn why the statement 'a[i] = i++' is undefined as per Standard C. The reason is that within two sequence points, the variable 'i' is modified and another access to 'i' is not for computing the value to be stored (modified value) instead it is being used as a subscript to an array 'a' and hence it violates the concept the Sequence Points in C.



Share/Save/Bookmark


No comments: