c++/970: Function execution order problem when using return value of funtions as parameter to another function.
skander@skander.com
skander@skander.com
Sun Dec 3 23:06:00 GMT 2000
>Number: 970
>Category: c++
>Synopsis: Function execution order problem when using return value of funtions as parameter to another function.
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: support
>Submitter-Id: net
>Arrival-Date: Sun Dec 03 23:06:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: Kai Schutte
>Release: gcc version 2.96 20000731 (Red Hat Linux 7.0)
>Organization:
>Environment:
>Description:
This is more of a standards question, but here goes...
This code:
int add_ten(int &num) { // changes num and returns 1.
num+10;
return 5;
}
void print(int num1, int num2, num3) {
cout << num1 << " " << num2 << " " << num3 << endl;
}
int main () {
int my_num = 10;
print(0, add_ten(my_num), my_num);
cout << my_num << endl;
}
should (IMHO) print out:
0 5 20
20
but instead prints:
0 5 10
20
I don't know if this is supposed to happen, and I don't
really know who to ask about this. Of course, it's easy
to change code so that this doesn't occur, but the real
question is how what this *should* print out... the
add_ten function is of course executed first, yet it's
changes aren't reflected in the parameters...
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-prs
mailing list