473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Order of evaluation -- clash w/sequentiel expression operator

Hi,
I was told that order of evaluation is unspecified for functions, i.e.

int f = 0;
print_results(modify(&f), modify(&f), modify(&f));

where i.e. modify() increases f by one. In my case w/gcc, it was evaluated from
right-to-left (gcc does a nice stack optimization). Not what I expected though.
Anyway:

Taking a look at the C operator precedence table, I find

, sequential expression left-to-right

at the bottom. So what's wrong here?

--
- Jan Engelhardt
Nov 13 '05 #1
2 2030
Jan Engelhardt <je*****@linux01.gwdg.de> wrote in
news:Pi*******************************@yvahk01.tjq t.qr:
Hi,
I was told that order of evaluation is unspecified for functions, i.e.

int f = 0;
print_results(modify(&f), modify(&f), modify(&f));

where i.e. modify() increases f by one. In my case w/gcc, it was
evaluated from right-to-left (gcc does a nice stack optimization). Not
what I expected though. Anyway:

Taking a look at the C operator precedence table, I find

, sequential expression left-to-right

at the bottom. So what's wrong here?


From memory, the comma as an operator and a comma in a function invokation
are different things entirely. The order of evaluation of function
arguments is undefined.

Ian Woods
Nov 13 '05 #2
In article <Pi*******************************@yvahk01.tjqt.qr >,
Jan Engelhardt <je*****@linux01.gwdg.de> wrote:
Hi,
I was told that order of evaluation is unspecified for functions, i.e.

int f = 0;
print_results(modify(&f), modify(&f), modify(&f));

where i.e. modify() increases f by one. In my case w/gcc, it was evaluated
from
right-to-left (gcc does a nice stack optimization). Not what I expected
though.
Anyway:

Taking a look at the C operator precedence table, I find

, sequential expression left-to-right

at the bottom. So what's wrong here?

You are confusing "comma expression" and function arguments. If you look
at the syntax of a function call you will find that the arguments are
not "expression"s but "assignment-expression"s. For example, the
comma-exppression x,y,z is _not_ an assignment expression, so f(x,y,z)
has three arguments, and not one.
Nov 13 '05 #3

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

Similar topics

0
by: Christos TZOTZIOY Georgiou | last post by:
Hi all, this post contains at the end a handy module that I've used quite often when I wanted to analyse the occasional complex expression and how it was to be evaluated. The function...
7
by: publictom | last post by:
Is the following statement true? "It is required that the operands to an operator be fully evaluated before the operator itself is evaluated." The only way I can think of that it would be...
8
by: der | last post by:
Hello all, I've a question about order of evaluations in expressions that have && and || operators in them. The question is: will the evalution go left-to-right, no matter what -- even if the...
21
by: dragoncoder | last post by:
Consider the following code. #include <stdio.h> int main() { int i =1; printf("%d ,%d ,%d\n",i,++i,i++); return 0; }
9
by: John Smith | last post by:
I've been playing with splint, which returns the following warning for the code below: statlib.c: (in function log_norm_pdf) statlib.c(1054,31): Expression has undefined behavior (left operand...
3
by: andreas ames | last post by:
Hi all, recently I came across a line of code like the following: if seq.erase(seq.begin(), seq.end()) != seq.end() /* ... */ It made me wonder if this is just bogus or if it even can...
15
by: Jeroen | last post by:
Hi all, I've got a very specific question about the evaluation order in C++. Assume some kind of custom array class, with an overloaded subscript operator. In the following code: { my_array...
32
by: silpau | last post by:
hi, i am a bit confused on expression evaluation order in expressions involving unary increment.decrement operators along with binary operators. For example in the following expression x...
54
by: Rasjid | last post by:
Hello, I have just joined and this is my first post. I have never been able to resolve the issue of order of evaluation in C/C++ and the related issue of precedence of operators, use of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
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...
0
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...
0
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,...

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.