[C-prog-lang-l] sequence points inquiry

Vladimír Kotal vlada at kotalovi.cz
Tue Feb 21 20:43:05 CET 2023


To add a bit more, the side effect/sequence point was mentioned in the context of the comma operator example https://github.com/devnull-cz/c-prog-lang/blob/master/src/comma.c

In the C99 spec there are these relevant sections:

6.5.2.4 about postfix increment/decrement operator says:

The side effect of updating the stored value of the operand shall occur between the previous and the next sequence point.

and in section 6.5.17 which describes the comma operator it says:

The left operand of a comma operator is evaluated as a void expression; there is a sequence point after its evaluation. Then the right operand is evaluated; the result has its type and value.

Hope this makes it more clear,

Best regards,


V. Kotal

On Mon, Feb 20, 2023, at 17:09, Jan Pechanec wrote:
> On Mon, 20 Feb 2023, Aryan Kumar wrote:
> 
> >Dear Professor,
> >
> >I asked you about side effects in the lecture today, when you mentioned
> >that sequence points are points in the program, where no more side effects
> >shall take place. I did some research and came to the conclusion that side
> >effects are any observable changes in the state of a program -- for
> >instance, memory writes, IO activity, function calls, exceptions, etc.
> >Furthermore, we can make some guarantees about the program state at a
> >sequence point.
> >
> >Please let me know if this understanding is flawed.
> >Besides that, I have another question about undefined and unspecified
> >behavior.
> >Is it true that undefined behavior results from program execution that is
> >not defined in the C specification -- like indexing outside bounds --
> >whereas unspecified behavior is when the program execution depends on the
> >compiler -- like adding integer function calls?
> 
> Please see types-of-behavior.md and undefined-behavior.md modules in 
> our github repository.
> 
> Regarding the side effect, please see 5.1.2.3 Program execution of the 
> C99 spec.  The link is on our web page at the end.
> 
> Jan
> 
> -- 
> Jan Pechanec <jp (at) devnull (dot) cz>
> http://www.devnull.cz
> _______________________________________________
> c-prog-lang-l mailing list
> c-prog-lang-l at mff.cuni.cz
> http://mbox.ms.mff.cuni.cz/listserv/listinfo/c-prog-lang-l
> 
-------------- next part --------------
HTML attachment scrubbed and removed


More information about the c-prog-lang-l mailing list