Hi all,
I came across some code and it's not clear why it is casting an unsigned char * to another pointer type only to free it right after.
Here are the relevant structures:
Code:
struct _Edje_Message
{
Edje *edje;
Edje_Queue queue;
Edje_Message_Type type;
int id;
unsigned char *msg;
Eina_Bool propagated : 1;
};
struct _Edje_Message_String
{
char *str; /* The message's string pointer */
};
struct _Edje_Message_Int
{
int val; /* The message's value */
};
As you can see, _Edge_Message has a *msg field, but in the function below, they cast it to the other two structure types inside the case blocks of the switch statement only to free it. What is the point or advantage of doing this?
Code:
void
_edje_message_free(Edje_Message *em)
{
if (em->msg)
{
int i;
switch (em->type)
{
case EDJE_MESSAGE_STRING:
{
Edje_Message_String *emsg;
emsg = (Edje_Message_String *)em->msg;
free(emsg->str);
free(emsg);
}
break;
case EDJE_MESSAGE_INT:
{
Edje_Message_Int *emsg;
emsg = (Edje_Message_Int *)em->msg;
free(emsg);
}
break;