RE: [LIP] Doubt in ++ operator
"Abdul Faruk" <[email protected]>
| Newsgroups | gmane.user-groups.linux.india.programmers |
|---|---|
| Message-ID | <D435FC6D9FB6F241B1A75DFB53784ADF03171D47@EMHQ05C.singtel.corp.root> |
Dear Amar,
Thanks for your reply.
But however in HP versions, we are able to get the said sequence.
Elsewhere in any o/s it is almost strange.
Thanks
Faruk
-----Original Message-----
From: linux-india-programmers-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
[mailto:linux-india-programmers-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org] On Behalf
Of Godbole, Amarendra (GE Consumer & Industrial)
Sent: Tuesday, July 27, 2004 12:53 PM
To: linux-india-programmers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: RE: [LIP] Doubt in ++ operator
> 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