🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #51738

Re: invalid lvalue between sequence points (was: bug ?)

#51738
From: Kevin Rodgers
Date: Mon, 05 Apr 1993 21:15
61 lines
3013 bytes
In article <1pl8ctINN757@senator-bedfellow.MIT.EDU> Stefano Casadei <casadei@cesena.mit.edu> writes:
>Can someone explain me the following behaviour ?
>Is it a bug ?

I think it qualifies as a bug, since the error report refers to an
operator (&) that does not appear in the source code.  If you do submit
a bug report to gnu.gcc.bug, please follow the instructions in gcc's
'Bug Reporting' info node.

>cesena-29->gcc -v
>Reading specs from /usr/local/lib/gcc-lib/sparc-sun/2.3.3/specs
>gcc version 2.3.3
>(sun4 with OS 4.1)
>
>
>The following lines:
>
>  vertebra* top = &(s[len]);
>  vertebra* t = s;
>  vertebra* u = v.s;
>  while (t < top) *t++ = *u++; // this is line 98
>
>cause the following error message:
>
>../prinst/vertebra.Vec.cc:98: invalid lvalue in unary `&'
>../prinst/vertebra.Vec.cc:98: invalid lvalue in unary `&'
>../prinst/vertebra.Vec.cc:98: please fix above errors, and try recompiling.

Hmmm.  Assuming for the moment left-to-right evaluation of the
assignment expression's operands, it says: set the vertebra to which t
points (s[0]) to the vertebra to which u points, incrementing t after t*
has been determined and incrementing u after u* has been determined.

As I understand it, the effect of the assignment on line 98 would be
undefined only if the incrementation of t or u had any side effect,
which neither does.  According to section 7.12 (Order of Evaluation) of
"C: A Reference Manual" (3rd edition) by Harbison & Steele:

|   In ANSI C, if a single object is modified more than once between
|successive sequence points, the result is undefined.  A sequence point
|is a point in the program's execution sequence at which all previous
|side effects of execution are to have taken place and at which no
|subsequent side effects will have occurred.  Sequence points occur:
|
|	* at the end of a full expression; that is, ... an
|	  expression statement, ...
|	...

>
>
>The following change fixes the problem:
>
>  vertebra* top = &(s[len]);
>  vertebra* t = s;
>  vertebra* u = v.s;
>  while (t < top) {*t++ = *u; u++;}
-- 
Kevin Rodgers				kevin@traffic.den.mmc.com
Martin Marietta MS A16401		(303) 790-3971
116 Inverness Dr. East
Englewood CO 80112 USA			GO BUFFS!
Technical Details
Message-ID: <9304052104.AA15065@traffic.den.mmc.com>
Path: arc1-ca.pugleaf.net!gmd.de!Germany.EU.net!mcsun!uunet!usc!howland.reston.ans.net!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!traffic.den.mmc.com!kevin
References: <1pl8ctINN757@senator-bedfellow.MIT.EDU>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,63b0a06876fed2ee
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-04-06 05:40:00 PST
Path: arc1-ca.pugleaf.net!gmd.de!Germany.EU.net!mcsun!uunet!usc!howland.reston.ans.net!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!traffic.den.mmc.com!kevin
From: kevin@traffic.den.mmc.com (Kevin Rodgers)
Newsgroups: gnu.gcc.help
Subject: Re: invalid lvalue between sequence points (was: bug ?)
Date: 5 Apr 1993 17:15:57 -0400
Organization: Martin Marietta Information Systems, WIS (Denver) Tech Ops
Lines: 61
Sender: daemon@cis.ohio-state.edu
Distribution: gnu
Message-ID: <9304052104.AA15065@traffic.den.mmc.com>
References: <1pl8ctINN757@senator-bedfellow.MIT.EDU>