While building the below code in eclipse I am getting void value not ignored as it ought to be, generally this error is encounter when we are expecting a value from a function returning void. But here I am not using any function, I am using a void pointer. Code is below:
typedef struct MessageName_T
{
MPM_ParameterName_t parameterName;
uint32_t minRange;
uint32_t maxRange;
bool_t isInRange;
DataType_t dataType;
bool_t isValueNa;
void* const data;
}MessageName_t ;
MessageName_t messagefr[3] =
/* Parameter, Minimum, Maximum, isInRange dataType isValueNa data*/
{
{ Parameter, Minimum, Maximum, isInRange, dataType, isValueNa, &stuctureA.data1},
{ Parameter1, Minimum1, Maximum1, isInRange1, dataType1, isValueNa1, &stuctureA.data2},
{ Parameter2, Minimum2, Maximum2, isInRange2, dataType2, isValueNa2, &stuctureA.data3}
}
void rangecheck(int index)
{
if(messagefr[index].isValueNa == FALSE)
{
if(*(messagefr[index].data) >= (messagefr[index].minRange) &&
*(messagefr[index].data) <= (messagefr[index].maxRange))
{printf("N");
messagefr[index].messagefr=TRUE;
}
else
{printf("Y");
messagefr[index].isInRange =FALSE;
}
}
else
{
NOP();
}
}
In line *(messagefr[index].data) >= (messagefr[index].minRange)
the error "void value not ignored as it ought to be" is coming. data is void pointer and I am assigning it the value of &stuctureA.data1
. Now while accessing this information of data ie *(messagefr[index].data)
I am getting the error, if I use (messagefr[index].data)
I am getting address assigned to data.
In your code, the data type of messagefr[index].data
is void *
, and you cannot dereference it.
You need to cast it to some other complete type before you can derefence it.
Considering you are comparing the value with minRange
, something like
*(uint32_t *)(messagefr[index].data)
will work.
To add some elaboration regarding the why part, first let's see about complete and incomplete types. Quoting
...] an object type may be incomplete (lacking sufficient information to determine the size of objects of that type) or complete (having sufficient information).
Now, coming to chapter §6.5.3.2, unary *
operator,
The unary
*
operator denotes indirection. If the operand points to a function, the result is a function designator; if it points to an object, the result is an lvalue designating the object. If the operand has type ''pointer to type'' , the result has type ''type'' . [...]
However, from chapter §6.2.5/19, we know
The
void
type comprises an empty set of values; it is an incomplete object type that cannot be completed.
Thus, a pointer to void
cannot be dereferenced because, the resulting type ( void
) is incomplete and the size required for the resulting object cannot be determined. so, we need to cast the pointer to a complete type before attempt to dereference.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.