delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/01/29/20:42:55

X-Spam-Check-By: sourceware.org
Message-ID: <43DD50A4.5446A7FE@dessent.net>
Date: Sun, 29 Jan 2006 15:32:52 -0800
From: Brian Dessent <brian AT dessent DOT net>
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: bizarre g++ behavior after reinstalling cygwin
References: <Pine DOT LNX DOT 4 DOT 63 DOT 0601291059100 DOT 14268 AT ajax DOT its DOT yale DOT edu>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id k0TNX7JP026279

Vadim Oganesyan wrote:

> Digging in I found that none of the "i=i++" calls inside for-loops work. I

Please get a book on C and then read it.  "i=i++" is undefined behavior
according to the standard, and upon seeing this the compiler is allowed
to do anything it wants -- it could generate code to format your hard
drive if it wanted to.  That your program even worked at any point with
any compiler is pure luck.

The reason it is undefined is because it attempts to modify 'i' in two
places (through the assignment and through ths side effect of
++-postincrement) in the same sequence point.  This is undefined
according to §6.5.2.

But that aside, the expression "i=i++" is just nonsense.  If you want to
increment i, all you need is "i++", or if you're feeling verbose "i = i
+ 1" or "i += 1".  But "i=i++" is invalid, and should not be used in any
C program.

See also:
<http://c-faq.com/ansi/undef.html>
<http://c-faq.com/expr/evalorder1.html>

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019