LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Error: invalid lvalue in assignment (https://www.linuxquestions.org/questions/linux-software-2/error-invalid-lvalue-in-assignment-473874/)

xxrsc 08-14-2006 06:15 PM

Error: invalid lvalue in assignment
 
I'm trying to compile irmp3-v0.5.6 but I have the following error.

irmp3mod.c: In function ‘mod_sendmsg’:
irmp3mod.c:103: error: invalid lvalue in assignment
make[2]: *** [irmp3mod.o] Error 1

Here's where I think the problem is:


Code:

// append message to queue
        for (m=mod_msgs; m && m->next; m=m->next);
        m ? m->next : mod_msgs = newmsg;


Here's the function:
Code:

void mod_sendmsg (int msgtype, char *msg)
{
        mod_message_t *newmsg, *m;
        log_printf(LOG_NOISYDEBUG,"CORE: message %s type %d sent",msg,msgtype);
        if(answer_head) { // we are in a query
                // the action has to be taken immediatly, so transform this to a query call
                // however, we don't care about the answer
                free_message(mod_query(msgtype,msg));
                // create new message entry
                newmsg = malloc(sizeof(mod_message_t));
                if (!newmsg) {
                        return;
                }
                newmsg->msg = malloc(strlen(msg)+1);
                if (!newmsg->msg) {
                        free(newmsg);
                        return;
                }
                newmsg->msgtype = msgtype;
                strcpy(newmsg->msg, msg);
                newmsg->next = NULL;
                answer_head->next = newmsg;
                answer_head = newmsg;
                return;
        }

        // create new message entry
        newmsg = malloc(sizeof(mod_message_t));
        if (!newmsg)
                return;
        newmsg->msg = malloc(strlen(msg)+1);
        if (!newmsg->msg) {
                free(newmsg);
                return;
        }
        newmsg->msgtype = msgtype;
        strcpy(newmsg->msg, msg);
        newmsg->next = NULL;

        // append message to queue
        for (m=mod_msgs; m && m->next; m=m->next);
        m ? m->next : mod_msgs = newmsg;
}

I've tried using and older version of gcc but then I get a bunch of other errors.

helmut_hed 08-17-2006 01:43 PM

That code is maybe a little too "clever" :)

I would first look at the type of m->next and mod_msgs and make sure they are still the same as the type of newmsg. If they are, I would try rewriting this line:

m ? m->next : mod_msgs = newmsg;

as this:

if (m) {
m->next = newmsg;
}
else {
mod_msgs = newmsg;
}

which should be equivalent. "invalid lvalue" means the left-hand-side of an assignment (the lvalue) is messed up. It could be a gcc version issue as you surmised.

Good luck,
Jeff


All times are GMT -5. The time now is 01:07 AM.