Function call evaluation order
- From: "Cheng" <chengwuchew@xxxxxxxxxxx>
- Date: Thu, 23 Mar 2006 09:30:15 +0800
Hi folks,
I need help to explain the behavior with the code below. I would like to
chain up function call into a single line, while the order of the function
call is correct, I cannot be certain with order the expression within the
function call is evaluated.
Woud it be better, then, to write all the function call into seperate lines?
With regards,
Cheng Wu
Code:
#include <stdio.h>
#include <string>
using namespace std;
void main()
{
char* data[] = {" zero ", " one ", " two ", " three "};
string s;
int i;
i = 0;
s.assign(data[i++]).append(data[i++]).append(data[i++]);
printf("%s\n", s.c_str());
i = 0;
s.assign(data[++i]).append(data[++i]).append(data[++i]);
printf("%s\n", s.c_str());
i = 0;
s.assign(data[i++]);
s.append(data[i++]);
s.append(data[i++]);
printf("%s\n", s.c_str());
}
Output:
zero zero zero
three three three
zero one two
.
- Follow-Ups:
- Re: Function call evaluation order
- From: Frederico Pissarra
- Re: Function call evaluation order
- From: Igor Tandetnik
- Re: Function call evaluation order
- Prev by Date: Re: /MT and /MD
- Next by Date: Re: /MT and /MD
- Previous by thread: 2 loose questions
- Next by thread: Re: Function call evaluation order
- Index(es):