This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: bizarre g++ behavior after reinstalling cygwin
- From: Brian Dessent <brian at dessent dot net>
- To: cygwin at cygwin dot com
- Date: Sun, 29 Jan 2006 15:32:52 -0800
- Subject: Re: bizarre g++ behavior after reinstalling cygwin
- References: <Pine.LNX.4.63.0601291059100.14268@ajax.its.yale.edu>
- Reply-to: cygwin at cygwin dot com
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/