RE: [LIP] Undefined behaviour ?

Sirish Kumar <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Organization Samsung ISO
Message-ID <!~!UENERkVCMDkAAQACAAAAAAAAAAAAAAAAABgAAAAAAAAAEKk8vB6X7kmIV+IQXmK9GsKAAAAQAAAAc5Oh2ByBa0GNqDs0n7JTYgEAAAAA@samsung.com>
Hi,

|-----Original Message-----
|From: linux-india-programmers-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org 
|On Behalf Of Mithun Bhattacharya
|Subject: [LIP] Undefined behaviour ?
|
|
|-----------------
|#include <stdio.h>
|main() {
|int i = 4;
|/* int j = i+++++i+i+++++i; */
|/* int j = i++ + ++i + i++ + ++i ; */
|int j = (i++)+(++i)+(i++)+(++i);
|printf("%d\n", j);
|}
|-----------------
|
<snip>
|
|Obviously none of them match what gcc is coming up with. Could someone
|please explain what is happening here ?
|
From my limited knowledge, I know that all this is purely compiler
dependent. You run this code on other machines like SUN, HP also, and
you would get different results. I don't think there is a compiler
'standard' which tells how to evaluate and optimize such expressions. 
So, IMHO this kind of coding should be avoided for (atleast) commercial
products.

Regards
Sirish



-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
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.