Passing Output of One Function to Another Function 1.0.1 vs 1.6.1


i updated 1.0.1 1.6.1 , noticed odd issue when running application. tracked down series of functions sharing reference parameter. below simple example demonstrate difference. there no reason did other seemed convenient , saved line of code. have no problem splitting code 2 lines, curious changed compiler or if there basic programming concept missing.

this print '5' in 1.0.1 , '0' in 1.6.1.

code: [select]

#include <arduino.h>

void setup() {
  serial.begin(9600);
  int = 0;
  func2(func1(a), a);
}

void loop() { }

int func1(int &b) {
   b = 5;
   return 0;
}

void func2(int c, int d) {
  serial.println(c + d);
}

func1 returns zero.

a 0 @ time of call func2.

the call func2 looks this:

func2(0, 0);


you cannot guarantee order parameters evaluated in. 'a' passed value second parameter change reference has no effect (parameters have been evaluated in reverse order).

this effect of optimization, , result, has removed 'int a' altogether.


Arduino Forum > Using Arduino > Programming Questions > Passing Output of One Function to Another Function 1.0.1 vs 1.6.1


arduino

Comments