🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #575

Re: No sequence points in assignment

#575
From: Jeffrey Kegler
Date: Wed, 13 Sep 1989 00:52
22 lines
1360 bytes
In article <1021@m3.mfci.UUCP> karzes@mfci.UUCP (Tom Karzes) writes:
>Consider the following statement:
>
>    x = a + (x = b);
>
>Could the assignment for (x = b) be performed after the outer
>assignment?

In ANSI C (3.3), this is undefined behavior, meaning anything (core
dump, generation of random number, etc.) can happen.  In all
likelihood, and in Classic C, you get the assignments performed in
whatever order amuses the compiler.

In any case, the practical implications are the same.  Anyone coming
across statements like this in code should rearrange them to introduce
a sequence point.  Breaking the above into two statements, or
rearrangement around a comma operator, will do it in the above.
-- 

Jeffrey Kegler, Independent UNIX Consultant, Algorists, Inc.
jeffrey@algor2.ALGORISTS.COM or uunet!algor2!jeffrey
1762 Wainwright DR, Reston VA 22090
Technical Details
Message-ID: <1989Sep13.005247.20121@algor2.algorists.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!brutus.cs.uiuc.edu!ginosko!uunet!algor2.algorists.com!jeffrey
References: <1021@m3.mfci.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!brutus.cs.uiuc.edu!ginosko!uunet!algor2.algorists.com!jeffrey
From: jeffrey@algor2.algorists.com (Jeffrey Kegler)
Newsgroups: comp.std.c
Subject: Re: No sequence points in assignment
Message-ID: <1989Sep13.005247.20121@algor2.algorists.com>
Date: 13 Sep 89 00:52:47 GMT
References: <1021@m3.mfci.UUCP>
Reply-To: jeffrey@algor2.UUCP (Jeffrey Kegler)
Distribution: comp
Organization: Algorists, Inc.
Lines: 22