From: kumaran subramanian [mailto:[EMAIL PROTECTED]
>Hi Ashwin & Paul,
>
>I think the answer given by Paul is correct. But i have a
>different reasoning for that answer. Normally C process the
>data from right to left for eg:printf("%d %d %d ",x,x<<2,x>>2);
No. C normally processes the expressions in such a statement in an
implementation specific manner. This need not be documented by the
compiler writer. If you want to know what C does, get a copy of The
Standard, and read the relevant sections. Don't base your conclusions on
empirical evidence.
It's arguments like this that lead to related arguments about the order
of evaluation of expressions such as:
foo() + bar() * baz()
The argument being that since * takes precidence over +, then bar() and
baz() are evaluated first (they might, they might not.) This leads to
(false) conclusion that you can dictate to the compiler/runtime in what
order you want the expressions evaluated. This is all nonsense, and if
anyone finds themselves relying on a particular order of evaluation
(between sequence points of course) then they should rethink how they're
coding.
For example, I can change the order of evaluation merely by adding an
option to the command line - notice that the last option '/O1' on the
first compile (optimise for space) is omitted on the second compile (no
opimisation on that compile - the rest of the options are identical
between the two and are irrelevant for the topic under consideration):
$ type c.c
#include <stdio.h>
int one(void){ return printf("1");}
int two(void){ return printf("22");}
int three(void){ return printf("333");}
int main(void){
printf("(1+2)*3\n");
printf("\n%d", (one() + two()) * three());
printf("\n\n1*(2+3)\n");
printf("\n%d", one() * (two() + three()));
}
$ make clean
rm *.obj c.exe .depend
touch .depend
$ make
cl c.c /EHs /Zc:forScope /Wall /W4 /WL /wd4820 /wd4619 /wd4217 /wd4710
/wd4668 /c /O1
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for
80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
c.c
link c.obj /OUT:c.exe /nologo
$ c
(1+2)*3
221333
9
1*(2+3)
333221
5
$ make clean
rm *.obj c.exe .depend
touch .depend
$ make
cl c.c /EHs /Zc:forScope /Wall /W4 /WL /wd4820 /wd4619 /wd4217 /wd4710
/wd4668 /c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for
80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.
c.c
link c.obj /OUT:c.exe /nologo
$ c
(1+2)*3
122333
9
1*(2+3)
122333
5
$
>This behaviour is happens in majority of the cases but also
>from left to right processing is possible.
Hardly majority as I've shown above .
>Basically this direction of processing is guided by the way
>in which stack is implemented.
.. or command line options supplied to the compiler, or which headers
have been included, or the phase of the moon....
--
PJH
bug, n: An elusive creature living in a program that makes it incorrect.
The activity of "debugging", or removing bugs from a program, ends when
people get tired of doing it, not when the bugs are removed. -
"Datamation", January 15, 1984
Alderley plc, Arnolds Field Estate, The Downs, Wickwar, Gloucestershire, GL12
8JD, UK
Tel: +44(0)1454 294556 Fax: +44 (0)1454 299272
Website : www.alderley.com Sales : [EMAIL PROTECTED] Service : [EMAIL
PROTECTED]
This email and its contents are confidential and are solely for the use of the
intended recipient. If you are not the original recipient you have received it
in error and any use, dissemination, forwarding, printing or copying of this
email is strictly prohibited. Should you receive this email in error please
immediately notify [EMAIL PROTECTED]
This email has been scanned for viruses, however you should always scan emails
with your own systems prior to opening.
------------------------ Yahoo! Groups Sponsor --------------------~-->
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/EbFolB/TM
--------------------------------------------------------------------~->
To unsubscribe : [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To reply to this message, go to:
http://groups.yahoo.com/group/Programmers-Town/post?act=reply&messageNum=4978
Please do not reply to this message via email. More information here:
http://help.yahoo.com/help/us/groups/messages/messages-23.html
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Programmers-Town/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/