Error: Illegal pointer operation (tovalue) !

I have the following program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// code - 1
#include <stuff to be included>


void rmacro()
{

int* p1 = &v1;

const bool condi1 = *p1 > 0;

if(condi1){ do something}


}



which works perfectly but when I try to use function, it doesn't work:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 //code -2
#include <stuff to be included>

func(int *p1)
{

const bool condi1 = *p1 > 0;

if(condi1){ do something; }

return something ;
}


void rmacro()
{int *p1 = &v1;

func(*p1);


}



The second code shows error: Illegal pointer operation (tovalue).

And I am using this as a macro in CERN's ROOT (version 5.34/36) shell on Ubuntu 16.04. How can I solve this problem ? Where am I going wrong ?
It took some effort to turn that into something which could be compiled:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
int v1 = 1234;

int func (int *p1)
{
    const bool condi1 = *p1 > 0;

    if (condi1)
    { 
    // do something;
    }

    return 0 ;
}


void rmacro()
{
    int *p1 = &v1;

    func(p1);
}

int main()
{
    
}

Not sure what your original problem was, since I made so many changes.

Possibly it was at the line func(*p1);
Function func() expects a parameter of type int* (pointer to int) but it is being called with the argument *p which is of type int. Put simply, the function expected a pointer but it received an integer.
Understood the difference, now will apply this on my code and will report back. Thanks.
Topic archived. No new replies allowed.