H
Harry Ebbers
Hi,
For some piece of code (an if-statement with multiple function-calls
to the same get-function in its condition) QA-C gives the following
warning on the 2 and further times the function is called:
"The right operand of '&&', '||', '?' or ':' has side effects, and
will only be executed under certain conditions. This is unclear. Try
using an explicit condition."
According to our coding-standard we should solve this QA-C warning.
But we want to understand first why this warning occurs.
And there lies the problem. We are breaking our head over why we get
this warning, since the function it calls is a get-function which does
not alterate any values. Note: the get-function is located in a
different module file than the if-statement.
The code looks like this:
(Note: SOME_TYPE is an enum-type)
Module_A.c
static SOME_TYPE some_arr[SIZE];
extern SOME_TYPE get_value(int index)
{
SOME_TYPE status = SOME_VALUE_0;
status = some_arr[index];
return status;
}
Module_B.c
#include <Module_A.h>
void function_with_QA_C_warning(void)
{
....
....
/* The lines marked with # are the lines where QA-C gives the
warning on */
if ((get_value(index1) == SOME_VALUE_1)
# || (get_value(index2) == SOME_VALUE_1)
# || (get_value(index3) == SOME_VALUE_1)
# || (get_value(index4) == SOME_VALUE_1))
{
....
}
....
}
Can anybody explain to us why QA-C sees these function-calls as calls
with side-effects?
Kind regards,
Harry Ebbers
For some piece of code (an if-statement with multiple function-calls
to the same get-function in its condition) QA-C gives the following
warning on the 2 and further times the function is called:
"The right operand of '&&', '||', '?' or ':' has side effects, and
will only be executed under certain conditions. This is unclear. Try
using an explicit condition."
According to our coding-standard we should solve this QA-C warning.
But we want to understand first why this warning occurs.
And there lies the problem. We are breaking our head over why we get
this warning, since the function it calls is a get-function which does
not alterate any values. Note: the get-function is located in a
different module file than the if-statement.
The code looks like this:
(Note: SOME_TYPE is an enum-type)
Module_A.c
static SOME_TYPE some_arr[SIZE];
extern SOME_TYPE get_value(int index)
{
SOME_TYPE status = SOME_VALUE_0;
status = some_arr[index];
return status;
}
Module_B.c
#include <Module_A.h>
void function_with_QA_C_warning(void)
{
....
....
/* The lines marked with # are the lines where QA-C gives the
warning on */
if ((get_value(index1) == SOME_VALUE_1)
# || (get_value(index2) == SOME_VALUE_1)
# || (get_value(index3) == SOME_VALUE_1)
# || (get_value(index4) == SOME_VALUE_1))
{
....
}
....
}
Can anybody explain to us why QA-C sees these function-calls as calls
with side-effects?
Kind regards,
Harry Ebbers