세 함수가 있는데, 각각 다음 함수를 호출하고 일부 값을 전달합니다. 이상하게도 두 번째 함수에서 세 번째 함수를 여러 번 호출하면 호출간에 값 중 하나가 변경됩니다. 그리고이 변수는 확실히 로컬입니다. 내가 누락 되었습니까?Arduino 함수 변수 값이 함수 호출간에 변경됩니다.
void functionA(...){
//Something...
int i=1,j=1,k=2;
functionB(i,j,k);
}
void functionB(int i,int j,int k){
String X="";
Serial.print(i);//Gives 1
if(j==1)
X="hello world";
functionC(i,j,k,X);//Call 1 to functionC
Serial.print(i);//Gives 0 !!!!!!!!!!!!!!!!!!!!!!!!
if(j==2)
X="hello world2";
functionC(i,j,k,X);//Call 2 to functionC
}
void functionC(int i, int j, int k, String X){
if(i)
//Do something
else
//Do somethingelse
}
내 실험
void functionC(int i, int j, int k, String X){
//Print i here. No difference with the result.
if(i)
//Do something
else
//Do somethingelse
//But if I Print i here again, then it is working. As in, "i" does not change anymore. between each call to functionC
}
예제에서 functionC를 한 번만 호출하면됩니다. – Willwsharp
죄송합니다. 업데이트 된 질문/코드 – aVC
두 번째 호출 후에 'i'를 다시 인쇄하십시오. – acornagl