RE: [LIP] Doubt in ++ operator

"Godbole, Amarendra \(GE Consumer & Industrial\)" <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Message-ID <[email protected]>
> int i=7; int j=i++ * i++; printf("%d",j);
> The above set of instruction will give you 7 * 8 = 56.

To add to previous posts, consider this expression:
j = i++ * ++i;

In this expression, in addition to undefined behavior that
is invoked (refer Binand's and Raj's post), you cannot
predict absolutely *anything* The C language does *not*
define the order of evaluation of sub-expressions in an
expression - so here you don't even know which one will be
evaluated first, i++ or ++i.

Best thing, IMHO, stay *away* from such expressions, and
never, ever make a mistake of using them in production
code.

Here is the definition of Undefined Behavior, from the
standard:

undefined behavior
Behavior, upon use of a nonportable or erroneous program 
construct, of erroneous data, or of indeterminately valued 
objects, for which this International Standard imposes no
requirements.

Which roughly translates to means - your compiler is free
to do *anything* if undefined behavior is invoked, which
can range from terminating the program, to getting 1000
pizzas' delivered to your doorstep, to charging your credit
card a transaction of USD 100,000. ;)

Cheers,
Amar

--
Infinity is where God is dividing by zero.


-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_idG21&alloc_id040&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.