Rule 19.1 and assignment of one element of array

Moderators: misra-c, david ward

Post Reply
lovewar
Posts: 10
Joined: Thu Feb 17, 2011 8:01 am
Company: .

Rule 19.1 and assignment of one element of array

Post by lovewar » Thu Oct 29, 2015 5:41 am

Would the following examples be compliant with rule #19.1?

Code: Select all

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 ?
}

misra-c
Posts: 560
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 19.1 and assignment of one element of array

Post by misra-c » Wed Nov 18, 2015 1:19 pm

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/ ... r_042.html) of the C standard, which stated that nonoverlapping portions of an array can be regarded as objects in their own right.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.19 Overlapping storage”