WeSearch

Sequence Points (2010)

·4 min read · 0 reactions · 0 comments · 11 views
#programming#c#undefined behavior
⚡ TL;DR · AI summary

The article discusses the concept of sequence points in C programming and how they affect the behavior of code. It highlights examples where modifying a variable multiple times between sequence points leads to undefined behavior. The author references the C99 standard to explain the implications of such programming practices.

Key facts
Original article
Susam
Read full at Susam →
Opening excerpt (first ~120 words) tap to expand

Sequence Points By Susam Pal on 26 May 2010 Code Examples A particular type of question comes up often in C programming forums. Here is an example of such a question: #include <stdio.h> int main() { int i = 5; printf("%d %d %d\n", i, i--, ++i); return 0; } On my system, the output was 5 6 5 with GCC and 6 6 6 with the C compiler that came with Microsoft Visual Studio. The versions of the compilers with which I got these results are: gcc (Debian 4.3.2-1.1) 4.3.2 Microsoft Visual Studio 2005 32-Bit C/C++ Optimizing Compiler Version 14.00.50727.42 for 80x86 Here is another example of such a question: #include <stdio.h> int main() { int a = 5; a += a++ + a++; printf("%d\n", a); return 0; } In this case, I got the output 17 with both these compiler versions.

Excerpt limited to ~120 words for fair-use compliance. The full article is at Susam.

Anonymous · no account needed
Share 𝕏 Facebook Reddit LinkedIn Threads WhatsApp Bluesky Mastodon Email

Discussion

0 comments

More from Susam