public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: gcc not warning on all occurences of operations with undefine d results?
@ 2005-11-15 23:27 Ryan Mansfield
  2005-11-16 11:08 ` Daniel Kabs
  0 siblings, 1 reply; 2+ messages in thread
From: Ryan Mansfield @ 2005-11-15 23:27 UTC (permalink / raw)
  To: 'Ladislav Mecir', Daniel Kabs; +Cc: gcc-help


> I think, that this is wrong. The exact rule should be more like "...if 
> the result of the operation is not defined by standard..."

The exact rule is in section 5.1.2.3 Paragraph 2

"Evaluation of an expression may produce side effects. At certain specified
points in the execution sequence called sequence points, all side effects of
previous evaluations shall be complete and no side effects of subsequent
evaluations shall have taken place."

Since there are no sequence points for the assignment, increment or index
operators, the behaviour is undefined.

Regards,

Ryan Mansfield

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: gcc not warning on all occurences of operations with undefine d results?
  2005-11-15 23:27 gcc not warning on all occurences of operations with undefine d results? Ryan Mansfield
@ 2005-11-16 11:08 ` Daniel Kabs
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Kabs @ 2005-11-16 11:08 UTC (permalink / raw)
  To: Ryan Mansfield; +Cc: 'Ladislav Mecir', gcc-help

Hello!

On Wednesday 16 November 2005 00:26, Ryan Mansfield wrote:
>>> ... if I have an
>>> expression and somewhere in that expression, I use an increment
>>> (decrement) operator on a variable, I can not mention that variable
>>> elsewhere in the expression. 
>>
>> I think, that this is wrong. The exact rule should be more like "...if
>> the result of the operation is not defined by standard..."
>
> The exact rule is in section 5.1.2.3 Paragraph 2

I just wanted to give a "rule of thumb". To help fellow programmers to avoid 
that trap.

Granted, my "rule of thumb" is not 100% correct but if you adhere to it, you 
avoid most of the problematic uses of ++ and --. And it's easy to 
remember. :-)

I think, a lot easier than what I found here:
http://c0x.coding-guidelines.com/6.5.html

| 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 read only to determine the value to be
| stored. 

| Except as specified later, the order of evaluation of subexpressions and the
| order in which side effects take place are both unspecified. 

What about rephrasing the "rule" as:
"If I have an assignment and somewhere in that assignment, I use an increment
(decrement) operator on a variable, I should not mention that variable 
elsewhere in the assignment".

Cheers
Daniel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-11-16 11:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-15 23:27 gcc not warning on all occurences of operations with undefine d results? Ryan Mansfield
2005-11-16 11:08 ` Daniel Kabs

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).