3 Replies - 562 Views - Last Post: 13 August 2008 - 10:00 AM Rate Topic: -----

#1 Sepanto  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 20-March 08

Order of evaluation of func. paramaters.

Post icon  Posted 13 August 2008 - 08:58 AM

Hi there!

Suppose I have a function void foo(int x, int y, int z);
and I write the next line
foo(x,++x,--x);

.

Is the line equivelent to
 
foo(x,x,x);


or to
foo(x,x+1,x-1);


?

Thanks in advance.

This post has been edited by Sepanto: 13 August 2008 - 08:59 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Order of evaluation of func. paramaters.

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Order of evaluation of func. paramaters.

Posted 13 August 2008 - 09:12 AM

This is not defined in C/C++. Different compilers will evaluate this differently.

In general you should not use multiple the ++ and -- operators in the same line of code. You should never use multiple ++ -- operators on the same variable in the same line of code. The results will be unpredictable.
Was This Post Helpful? 0
  • +
  • -

#3 Sepanto  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 97
  • Joined: 20-March 08

Re: Order of evaluation of func. paramaters.

Posted 13 August 2008 - 09:14 AM

Thanks!!
And if I have the line
foo(++x,x,x);


is it equivallent to
foo(x+1,x,x);


or to
foo(x+1,x+1,x+1);


Was This Post Helpful? 0
  • +
  • -

#4 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Order of evaluation of func. paramaters.

Posted 13 August 2008 - 10:00 AM

:) Again this is undefined. The order of evaluation of the parameters to a function are compiler specific (and actually sometimes optimization specific).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1