[previous] 3345 [next] Statement contains more than one access to objects that are volatile.
Side Effects REFERENCE - ISO:C90-5.1.2.3 Program Execution

This statement contains more than one access to objects that are 'volatile'.

Any operation which reads from or writes to a volatile object, may induce side effects. If more than one side effect takes place between sequence points, it is important to ensure that the order in which they take place is not significant.

One way in which to ensure safer use of volatile objects is to severely restrict the way in which they are accessed:

For example:


/*PRQA S 506,2100,3120,3132,3198,3199,3203,3408,3441,3447,3602 ++*/

extern volatile unsigned char vp1;
extern volatile unsigned char vp2;
extern          unsigned char buf[10];

extern unsigned char func(unsigned char p);

extern void foo ( void )
{
    volatile unsigned char *pno1;
    volatile unsigned char *pno2;
    unsigned char           r;

    pno1 = &vp1;                        /*                     */
    pno2 = &vp2;                        /*                     */
    r = *pno1;                          /*                     */
    r = vp1;                            /*                     */
    vp2 = r;                            /*                     */

    r = buf[vp1];                       /* Message 3442        */
    r = buf[*pno2];                     /* Message 3442        */
    r = func(vp1);                      /* Message 3442        */
    r += vp1;                           /* Message 3442        */

    r = func(vp1) + func(vp2);          /* Message 3442 + 3345 */
    r = *pno1 + *pno2;                  /* Message 3442 + 3345 */
    r = vp1 + vp2;                      /* Message 3442 + 3345 */
    r = vp1 + buf[vp2];                 /* Message 3442 + 3345 */
    r = vp1 + (vp1 << 4);               /* Message 3442 + 3345 */
    vp1 = func(vp2);                    /* Message 3442 + 3345 */

    *pno2 = *pno1;                      /* Message        3345 */
    vp1 = vp2;                          /* Message        3345 */
}


No MISRA C:2012 Rules applicable to message 3345


See also:

QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents