Invalid operands
-
I am trying to calculate sum of fibonacci series. Struct arg is defined in header file as follows
struct args {
int number;
int result;
};args user_arguments = { 10, 0 };
void fibonacci (void* arguments)
{
args* local_args = (args*) arguments;
printf("local_args->number = %d\n", local_args->number);
if (local_args->number <= 1) {
local_args->result= 1;
return;
}
int a = (local_args->number)-1;
int b = (local_args->number)-2;
local_args->result =fibonacci(&a) + fibonacci(&b)
return local_args->result;Above function is called from the function below. createPackage is a function provided by another library which gonna execute fabonacci function.
void WorkPackage(void*) {
createPackage(fibonacci, &user_arguments);
printf("Sum of fabonacci sequence is %d ", args->result) }While compiling, It gives the following error
invalid operands of types ‘void’ and ‘void’ to binary ‘operator+’
Please help in pointing what am i doing wrong here??
-
I am trying to calculate sum of fibonacci series. Struct arg is defined in header file as follows
struct args {
int number;
int result;
};args user_arguments = { 10, 0 };
void fibonacci (void* arguments)
{
args* local_args = (args*) arguments;
printf("local_args->number = %d\n", local_args->number);
if (local_args->number <= 1) {
local_args->result= 1;
return;
}
int a = (local_args->number)-1;
int b = (local_args->number)-2;
local_args->result =fibonacci(&a) + fibonacci(&b)
return local_args->result;Above function is called from the function below. createPackage is a function provided by another library which gonna execute fabonacci function.
void WorkPackage(void*) {
createPackage(fibonacci, &user_arguments);
printf("Sum of fabonacci sequence is %d ", args->result) }While compiling, It gives the following error
invalid operands of types ‘void’ and ‘void’ to binary ‘operator+’
Please help in pointing what am i doing wrong here??
You are trying to add two operands of the type void (fibonacci(&a)and fibonacci(&b)) :
meerokh wrote:
local_args->result =fibonacci(&a) + fibonacci(&b)
and the compiler doesn't know how to do it!
-
You are trying to add two operands of the type void (fibonacci(&a)and fibonacci(&b)) :
meerokh wrote:
local_args->result =fibonacci(&a) + fibonacci(&b)
and the compiler doesn't know how to do it!
-
I am trying to calculate sum of fibonacci series. Struct arg is defined in header file as follows
struct args {
int number;
int result;
};args user_arguments = { 10, 0 };
void fibonacci (void* arguments)
{
args* local_args = (args*) arguments;
printf("local_args->number = %d\n", local_args->number);
if (local_args->number <= 1) {
local_args->result= 1;
return;
}
int a = (local_args->number)-1;
int b = (local_args->number)-2;
local_args->result =fibonacci(&a) + fibonacci(&b)
return local_args->result;Above function is called from the function below. createPackage is a function provided by another library which gonna execute fabonacci function.
void WorkPackage(void*) {
createPackage(fibonacci, &user_arguments);
printf("Sum of fabonacci sequence is %d ", args->result) }While compiling, It gives the following error
invalid operands of types ‘void’ and ‘void’ to binary ‘operator+’
Please help in pointing what am i doing wrong here??
Your definition of the
fibonacci
function is incorrect. You cannot return a value from a function defined asvoid
, i.e. not returning anything. You also declare the arguments parameter as avoid*
but pass the address of anint
variable to it. You then cast that to the address of anargs
structure, which will likely cause a segmentation fault. You need to rethink this code completely. -
Have you tried having the
fibonacci()
function return a value, or if the function's signature is unchangeable, removing thereturn
statement? You might also consider terminating thelocal_args->result = fibonacci(&a) + fibonacci(&b)
statement with a semicolon."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
I am trying to calculate sum of fibonacci series. Struct arg is defined in header file as follows
struct args {
int number;
int result;
};args user_arguments = { 10, 0 };
void fibonacci (void* arguments)
{
args* local_args = (args*) arguments;
printf("local_args->number = %d\n", local_args->number);
if (local_args->number <= 1) {
local_args->result= 1;
return;
}
int a = (local_args->number)-1;
int b = (local_args->number)-2;
local_args->result =fibonacci(&a) + fibonacci(&b)
return local_args->result;Above function is called from the function below. createPackage is a function provided by another library which gonna execute fabonacci function.
void WorkPackage(void*) {
createPackage(fibonacci, &user_arguments);
printf("Sum of fabonacci sequence is %d ", args->result) }While compiling, It gives the following error
invalid operands of types ‘void’ and ‘void’ to binary ‘operator+’
Please help in pointing what am i doing wrong here??
You have to comply with the assigned interface, but such interface would probably make your Fibonacci series computation rather clumsy. I suggest you to separate the tasks: write a
fibonacci
function complying with the required interface wich, in turn, calls a trivial recursive implementation (saymyfib
) of the series computation:#include struct args
{
int number;
int result;
};// trivial recursive implementation on Fibonacci series computation
static int myfib( int n )
{
if ( n < 3 )
return 1;
else
return myfib(n-1) + myfib(n-2);
}// the interface compliant function
void fibonacci( void * arguments )
{
struct args * pargs = (struct args *) arguments;
pargs->result = myfib( pargs->number); // call the private workhorse
}// test program
int main()
{
struct args a = { 10, 0 };
fibonacci( &a );
printf("fibonacci(%d)=%d\n", a.number, a.result);
return 0;
}