how to avoid compilation error: expression must be a modifiable lvalue

3 vues (au cours des 30 derniers jours)
Bong-Kee Choi
Bong-Kee Choi le 17 Jan 2013
Hi.
I met a compilation error with following code. a physical buffer (communication buffer of MCU) tossed to void* dest. if I change all argument to local variable and pointer compilation successful.
First I thought, polyspace doesn't understand typecasting of void to other, but I guess now when physical address is tossed as argument then it occur compilation error "expression must be a modifiable lvalue", since polyspace doesn't understand physical address.
Am i thinking correct? and does anybody can help me to avoid compilation error?
typedef unsigned char u08;
void* AL_MemCpy (void* dest, const void* source, u08 count)
{
while (count--)
{
*((u08*)dest)++ = *((u08*)source)++;
}
}
// used in other function like below
(void)AL_MEMCPY(RxBuffer,&(data[1]),(u08)RxMessage.Length);

Réponse acceptée

Jan
Jan le 17 Jan 2013
Modifié(e) : Jan le 17 Jan 2013
(u8 *) dest is a temporary variable, which cannot be increased. Perhaps you want this:
*((u08*)dest++) = *((u08*)source++);
But this copies the first byte only. Perhaps memcpy would be smarter?
Or:
u08 *d = (u08 *) dest, *s = (u08 *) source;
while (count--) {
*d++ = *s++;
}
  2 commentaires
James Tursa
James Tursa le 17 Jan 2013
Modifié(e) : James Tursa le 17 Jan 2013
+1 is for the last option shown, which I prefer since it is clear what is being done and avoids trying to apply the ++ operator to a (void *) type (which inherently doesn't make sense and isn't allowed since void is of unknown size) using fancy-mangled syntax (e.g., the first option shown above will not compile).
Bong-Kee Choi
Bong-Kee Choi le 17 Jan 2013
Actually this code cause MISRA Rule violation also. Even though it can be work with some compiler (Codewarrior) but compatibility can't be guaranteed.
Thanks to all.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur C Shared Library Integration dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by