MISRA Discussion Forums
Rule 19.1 and assignment of one element of array - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.19 Overlapping storage (https://forum.misra.org.uk/forumdisplay.php?fid=174)
+---- Thread: Rule 19.1 and assignment of one element of array (/showthread.php?tid=1208)



Rule 19.1 and assignment of one element of array - lovewar - 29-10-2015

Would the following examples be compliant with rule #19.1?
Code:
int16_t a[20];
void g(void)
{
    int16_t *p = &a[0];
    int16_t *q = &a[0];
    *p = *q;              /* Compliant - exception 1 */
}
void f(void)
{
    int16_t *p = &a[0];
    int16_t *q = &a[1];
    *p = *q;                     // here, is it Compliant ?
}



Re: Rule 19.1 and assignment of one element of array - misra-c - 18-11-2015

In function f the *p and *q are considered to be pointing to a different objects and therefore the assigment is compliant with rule 19.1.

This was clarified in DR#042 (http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_042.html) of the C standard, which stated that nonoverlapping portions of an array can be regarded as objects in their own right.