Skip to main content

Arduino - call Call by reference

I tryam trying to learn 'call by reference'. I want to call a function 'fcn1'fcn1 from the main loop and pass a reference of the local variable 'var'var to the function 'fcn1'fcn1. Next step is to call a second function 'fcn2'fcn2 from the function 'fcn1'fcn1 and pass again the reference of the local loop variable 'var'var. I allwaysalways get this error massage: "invalid conversion from 'int' to 'int*' [-fpermissive]".

invalid conversion from 'int' to 'int*' [-fpermissive]

Here a small example code:

void fcn1(int *variable)
{
  fcn2(&variable);
}

void fcn2(int *variable)
{
  //do something with the variable
}

void setup() {
{

}

void loop() {
{
  int var = 1000;
 
  fcn1(&var);
}

I tried to solve that issue by using:

void fcn1(int *variable)
{
  fcn2(*variable);
}

But it's the same error.

By deleting the ** respectively && it works fine, but is it still a reference?

Thanks in advance.

Dave

Arduino - call by reference

I try to learn 'call by reference'. I want to call a function 'fcn1' from the main loop and pass a reference of the local variable 'var' to the function 'fcn1'. Next step is to call a second function 'fcn2' from the function 'fcn1' and pass again the reference of the local loop variable 'var'. I allways get this error massage: "invalid conversion from 'int' to 'int*' [-fpermissive]".

Here a small example code:

void fcn1(int *variable)
{
  fcn2(&variable);
}

void fcn2(int *variable)
{
  //do something with the variable
}

void setup() {


}

void loop() {

int var = 1000;
 
fcn1(&var);
}

I tried to solve that issue by using:

void fcn1(int *variable)
{
  fcn2(*variable);
}

But it's the same error.

By deleting the * respectively & it works fine but is it still a reference?

Thanks in advance.

Dave

Call by reference

I am trying to learn 'call by reference'. I want to call a function fcn1 from the main loop and pass a reference of the local variable var to the function fcn1. Next step is to call a second function fcn2 from the function fcn1 and pass again the reference of the local loop variable var. I always get this error massage:

invalid conversion from 'int' to 'int*' [-fpermissive]

Here a small example code:

void fcn1(int *variable)
{
  fcn2(&variable);
}

void fcn2(int *variable)
{
  //do something with the variable
}

void setup()
{

}

void loop()
{
  int var = 1000;
  fcn1(&var);
}

I tried to solve that issue by using:

void fcn1(int *variable)
{
  fcn2(*variable);
}

But it's the same error.

By deleting the * respectively & it works fine, but is it still a reference?

Source Link
piiq
  • 11
  • 1
  • 1
  • 2

Arduino - call by reference

I try to learn 'call by reference'. I want to call a function 'fcn1' from the main loop and pass a reference of the local variable 'var' to the function 'fcn1'. Next step is to call a second function 'fcn2' from the function 'fcn1' and pass again the reference of the local loop variable 'var'. I allways get this error massage: "invalid conversion from 'int' to 'int*' [-fpermissive]".

Here a small example code:

void fcn1(int *variable)
{
  fcn2(&variable);
}

void fcn2(int *variable)
{
  //do something with the variable
}

void setup() {


}

void loop() {

int var = 1000;

fcn1(&var);
}

I tried to solve that issue by using:

void fcn1(int *variable)
{
  fcn2(*variable);
}

But it's the same error.

By deleting the * respectively & it works fine but is it still a reference?

Thanks in advance.

Dave