This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: bizarre g++ behavior after reinstalling cygwin


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]