This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

warning: #1441-D: nonstandard cast on lvalue

Hello guys, i am having this errore with the following code:

startLinst(Timer_u *head){ Timer_u *ptr;

(Timer_u *)ptr->list1->pnext = *head;
} where head is the pointer to the head of a linked list.

the ADT is:
typedef union TIMER_U{ Timer4 *timer4; Timer3 *timer3; Timer2 *timer2; Timer1 *timer1;
}Timer_u;

typedef struct TIMER1{ unsigned char TimerID; unsigned char cnt; unsigned char processo:6; unsigned char type:2; union Timer_u *pnext;
}Timer1;

Can anyone help me to avoid this warning message?

  • The instructions for posting source code are quite clearly stated:

    www.danlhenry.com/.../keil_code.png

    aren't they?

  • i haven't read it to be honest, I will rewrite it

    sorry for the incovenience.

  • I will re-write the code:

    startLinst(Timer_u *head){
        Timer_u *ptr;
    
        (Timer_u *)ptr->list1->pnext = *head;
    }
    

    where head is the pointer to the head of a linked list.

    the ADT is:

    typedef union TIMER_U{
        Timer4 *timer4;
        Timer3 *timer3;
        Timer2 *timer2;
        Timer1 *timer1;
    }Timer_u;
    
    typedef struct TIMER1{
        unsigned char TimerID;
        unsigned char cnt;
        unsigned char processo:6; unsigned char type:2;
        union Timer_u *pnext;
    }Timer1;
    

    Can anyone help me to avoid the warning message 1441?

  • There is a typo in your code:

    union Timer_u *pnext;
    


    The keyword union shouldn't be there. The compiler thinks that you are referring to a different type defined elsewhere, rather than to Timer_u.

  • Can anyone help me to avoid the warning message 1441?

    Remove the cast!

  • Mike, thanks for the hint, but removing the union I got the error "undefined class storage", so I put the code
    union TIMER_U before the definition of the structs timer1/2/3/4 and this will make the compiler happy.
    this will we work in your opinion?

    Jack, removing the cast I will get an error about an illegal assignment.

  • removing the union I got the error "undefined class storage", so I put the code union TIMER_U before the definition of the structs timer1/2/3/4 and this will make the compiler happy

    Isn't it "undefined storage class" instead?
    Besides, it seems to me it's not the right way to make the compiler happy. I think we're not seeing the whole picture: the code you posted is incomplete, it's not clear in what order things are declared and defined.

  • you are right some infos are missing:
    the ADT is defined in a header file, in the inverse order: i mean the struct is defined before the union
    this is the right order

    typedef struct TIMER1{
        unsigned char TimerID;
        unsigned char cnt;
        unsigned char processo:6; unsigned char type:2;
        union Timer_u *pnext;
    }Timer1;
    
    typedef struct TIMER2{...} Timer2;
    typedef struct TIMER3{...} Timer3;
    typedef struct TIMER4{...} Timer4;
    
    typedef union TIMER_U{
        Timer4 *timer4;
        Timer3 *timer3;
        Timer2 *timer2;
        Timer1 *timer1;
    }Timer_u;
    
    

    so I changed it in this way

    union TIMER_U;
    typedef struct TIMER1{
        unsigned char TimerID;
        unsigned char cnt;
        unsigned char processo:6; unsigned char type:2;
        union TIMER_U *pnext;
    }Timer1;
    
    typedef struct TIMER2{...} Timer2;
    typedef struct TIMER3{...} Timer3;
    typedef struct TIMER4{...}Timer4;
    
    typedef union TIMER_U{
        Timer4 *timer4;
        Timer3 *timer3;
        Timer2 *timer2;
        Timer1 *timer1;
    }Timer_u;
    
    

  • so I changed it in this way

    Yes, this new version of the code looks right.
    What about the code that throws the warning? Is the warning still there? Did you post the complete offending code?

  • I have removed the cast and the warning message is non more there :)
    thanks for you help.