473,546 Members | 2,289 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Order of parameter evaulation

Boy, I'll sure bet this is a FAQ.

Many years ago, my "runtime behavior of programming languages" prof
absolutely guaranteed that C parameters are evaluated left-to-right.

He was a bright guy from CMU whose research focus was on programming
languages, and I believed him, but now I'm not so sure.

Little help?

--
Bush is blowing it.
Nov 13 '05 #1
13 2638
Richard <rh***@hotmail. com> wrote:
Boy, I'll sure bet this is a FAQ. Many years ago, my "runtime behavior of programming languages" prof
absolutely guaranteed that C parameters are evaluated left-to-right. He was a bright guy from CMU whose research focus was on programming
languages, and I believed him, but now I'm not so sure. Little help?


You're right, this is in the FAQ.

http://www.eskimo.com/~scs/C-faq/top.html

Or, more specifically:

http://www.eskimo.com/~scs/C-faq/q3.4.html

Alex
Nov 13 '05 #2
Richard wrote:
Boy, I'll sure bet this is a FAQ.

Many years ago, my "runtime behavior of programming languages" prof
absolutely guaranteed that C parameters are evaluated left-to-right.

He was a bright guy from CMU whose research focus was on programming
languages, and I believed him, but now I'm not so sure.


It's good not to be so sure: either he's wrong or your understanding of
what he said is wrong.
--
Martin Ambuhl

Nov 13 '05 #3
Richard wrote:

Boy, I'll sure bet this is a FAQ.

Many years ago, my "runtime behavior of programming languages" prof
absolutely guaranteed that C parameters are evaluated left-to-right.

He was a bright guy from CMU whose research focus was on programming
languages, and I believed him, but now I'm not so sure.

Little help?


http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/

N869
3.19
[#1] unspecified behavior
behavior where this International Standard provides two or
more possibilities and imposes no requirements on which is
chosen in any instance

[#2] EXAMPLE An example of unspecified behavior is the
order in which the arguments to a function are evaluated.
Nov 13 '05 #4
al*******@hotma il.com wrote...
Richard <rh***@hotmail. com> wrote:
Boy, I'll sure bet this is a FAQ.

Many years ago, my "runtime behavior of programming languages" prof
absolutely guaranteed that C parameters are evaluated left-to-right.

He was a bright guy from CMU whose research focus was on programming
languages, and I believed him, but now I'm not so sure.

Little help?


You're right, this is in the FAQ.

http://www.eskimo.com/~scs/C-faq/top.html

Or, more specifically:

http://www.eskimo.com/~scs/C-faq/q3.4.html


Thanks--I saw that. I was thinking more like, for example,

if ( cond1 && (cond2 || cond3) ) {...}

is there a predictable order of parameter evaluation? My experience
is that this is undefined and compiler-specific.

I'm really sure about what he said, because we talked about it a few
times afterwards in the context of using the behavior in production
programs.

--
Bush is blowing it.
Nov 13 '05 #5
pf*****@mindspr ing.com wrote...
Richard wrote:

Boy, I'll sure bet this is a FAQ.

Many years ago, my "runtime behavior of programming languages" prof
absolutely guaranteed that C parameters are evaluated left-to-right.

He was a bright guy from CMU whose research focus was on programming
languages, and I believed him, but now I'm not so sure.

Little help?


http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/

N869
3.19
[#1] unspecified behavior
behavior where this International Standard provides two or
more possibilities and imposes no requirements on which is
chosen in any instance

[#2] EXAMPLE An example of unspecified behavior is the
order in which the arguments to a function are evaluated.


Perfect. Thank you very much. (My prof was right about everything
else!)

--
Bush is blowing it.
Nov 13 '05 #6
In article <MP************ ************@ne ws.verizon.net> ,
Richard <rh***@hotmail. com> wrote:
N869
3.19
[#1] unspecified behavior
behavior where this International Standard provides two or
more possibilities and imposes no requirements on which is
chosen in any instance

[#2] EXAMPLE An example of unspecified behavior is the
order in which the arguments to a function are evaluated.


Perfect. Thank you very much. (My prof was right about everything
else!)


But in another post, you ask about:
if (cond1 || cond2) {
[ ... ]
}
In that case, cond1 is guaranteed to be completely evaluated before
cond2. (And cond2 is guaranteed to be evaluated if and only if cond1
is zero.)

-- Brett
Nov 13 '05 #7
Richard <rh***@hotmail. com> wrote:
al*******@hotma il.com wrote...
Richard <rh***@hotmail. com> wrote:
> Boy, I'll sure bet this is a FAQ.

> Many years ago, my "runtime behavior of programming languages" prof
> absolutely guaranteed that C parameters are evaluated left-to-right.

> He was a bright guy from CMU whose research focus was on programming
> languages, and I believed him, but now I'm not so sure.

> Little help?


You're right, this is in the FAQ.

http://www.eskimo.com/~scs/C-faq/top.html

Or, more specifically:

http://www.eskimo.com/~scs/C-faq/q3.4.html


Thanks--I saw that. I was thinking more like, for example,

if ( cond1 && (cond2 || cond3) ) {...}

is there a predictable order of parameter evaluation? My experience
is that this is undefined and compiler-specific.


The && and || operators are something of a special case because they
(like the , and ?: operators) introduce additional sequence points. In
the expression:

a && (b || c)

Then a is completely evaluated first, and all side-effects happen. If a
was zero, then the result of the complete expression is zero and no
further evaluation happens. Otherwise, b is completely evaluated and
all side-effects take place - if b was non-zero, the result of the
complete expression is 1 and no further evaluation happens. Otherwise,
c is evaluated and the result of the complete expression is zero if c
was zero, otherwise it is 1. Any side-effects caused by evaluating c do
not necessarily take effect until the next sequence point.

On the other hand, in:

a & (b | c)

....then all of a, b and c are evaluated (unless the compiler can prove
that no visible side-effects result from some evaluation), in an
unspecified order. Any side-effects do not necessarily take effect
until the next sequence point.

- Kevin.

Nov 13 '05 #8
Brett Frankenberger wrote:

In article <MP************ ************@ne ws.verizon.net> ,
Richard <rh***@hotmail. com> wrote:
N869
3.19
[#1] unspecified behavior
behavior where this International Standard provides two or
more possibilities and imposes no requirements on which is
chosen in any instance

[#2] EXAMPLE An example of unspecified behavior is the
order in which the arguments to a function are evaluated.


Perfect. Thank you very much. (My prof was right about everything
else!)


But in another post, you ask about:
if (cond1 || cond2) {
[ ... ]
}
In that case, cond1 is guaranteed to be completely evaluated before
cond2. (And cond2 is guaranteed to be evaluated if and only if cond1
is zero.)


.... which has nothing to do with parameters.
Parameters are the local objects in functions
which get initialized to the argument values in a function call

--
pete
Nov 13 '05 #9
Richard <rh***@hotmail. com> writes:
Richard <rh***@hotmail. com> wrote:
Many years ago, my "runtime behavior of programming languages" prof
absolutely guaranteed that C parameters are evaluated left-to-right.

Wrong. There is no such guarantee. In fact, I suspect that many
implementations always evaluate parameters from right to left.
Thanks--I saw that. I was thinking more like, for example,

if ( cond1 && (cond2 || cond3) ) {...}

is there a predictable order of parameter evaluation?


There aren't any parameters there, just operands. Functions have
parameters (the expression supplied as a parameter value is
called an argument), whereas operators have operands. && and ||
are special--they always evaluate their left operands first, and
then the right operand only if necessary. Most other operators
do not share this guarantee.
--
"It wouldn't be a new C standard if it didn't give a
new meaning to the word `static'."
--Peter Seebach on C99
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3199
by: One's Too Many | last post by:
Ran into a strange problem today: 8.1.7 on AIX 4.3.3 Database and applications had been working fine for two years and all of a sudden a couple of regularly-run queries are now no longer coming out in correct sort order specified in the ORDER clauses of the select statements. Behavior is erratic, about half the time the sort order is...
4
8244
by: dave | last post by:
hi all, hope someone can help.... i'm having trouble calling an SP where the ORDER BY operator is specified as a parameter when the SP is called my SP is..... CREATE PROCEDURE dbo.sp_CustSearch (@SearchFor VARCHAR(80) , @SortOrder VARCHAR(50)) AS
6
1434
by: lig | last post by:
hi , i am trying to do something that is not working (cuz i tried that) so i hope for some ideas about it. ok, so i have this recursive function, lets call it recFun and i wanted to be able to call it in a specific order. in a simple way : evaluating some expression in its original order see the following part of code:
1
1451
by: Hrvoje Vrbanc | last post by:
Hello all! I would be grateful if someone could offer me some help with the following problem: I have a DataGrid control with sort enabled. Therefore it could be sorted in several different ways. The same datagrid also have a Button Column with Update button. After the update action for any particular item is completed, my update method...
3
1956
by: Jesper Jensen | last post by:
I have the following problem: I have created the following SQL for my app. With the below shown code (Example 1) I am able to retrieve the records I need into dataset dsFind. Now however I want to do another search as in Example 2, this doesnt work and I get no records. However if I switch around the order of the parameters as seen in...
1
4644
by: Thomas Schoen | last post by:
Hi, is it possible to use a parameter of a plpgsql-function to order a selection inside the function? What i would like to do is pass a column-name/alias-name to a plpgsql function and use the variable as order-by-parameter like this: create function foo(varchar) RETURNS SETOF test AS '
3
3651
by: Beowulf | last post by:
I was just messing around with some ad hoc views and table returning UDFs today so I could look at and print out data from a small table and noticed something strange. If I stick my select statement into a View the columns are returned in the order I specify in the SELECT, but if the same statement is in a UDF (so I can specify a...
11
9670
by: Israel | last post by:
I've trying to write a query that seems like it should be simple but for some reason my attempts are not working. This is really a general SQL quesion and doesn't pertain to MySQL but I couldn't find a generic database discussion group except on on advancement and theory and this is really a basic query construction question. Just say I...
3
2998
by: altafur | last post by:
hi, i am using java with hibernate . i want to run a hibernate order by query thru java. i have written the query in hibernate.hbm.xml file. the query is as follows: query: SELECT distinct a.process_id, a.name name, a.category_id,c.parent_id FROM tbl_process_master a, tbl_category c where (lower(a.name) like :searchString or...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7792
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.