![]() |
![]() |
0402 | ![]() |
||||
![]() | |||||||
| Explicitly undefined | REFERENCE - ISO:C90-6.3 Expressions | ||||||
An object is being both modified and accessed between sequence points. The ISO:C Standard says that if an object is modified and accessed other than to determine the new value between sequence points, the result will be undefined. If the value of an object is being used and the value is also being modified within a statement, it is important to know whether the modification will occur before or after its value is used. Unfortunately this is not always defined in the C language. Message 0402 is generated when the ordering of an access to an object and a definite modification of the object are undefined. Definite sources of modification are associated with assignment operations and increment and decrement operations. In the code examples shown below:
/*PRQA S 506,2017,3120,3199,3408,3416,3422,3440,3441,3447,3673 ++*/
extern void func(int x, int y);
extern void foo(int buf[], int index)
{
int r;
r = (2 * index) + index++; /* a) Message 0402 */
buf[++r] == buf[r]; /* b) Message 0402 */
func(r, r++); /* c) Message 0402 */
r = r + 1; /* d) OK */
}
MISRA C:2012 Rules applicable to message 0402:
| Rule-1.3 (Required) | There shall be no occurrence of undefined or critical unspecified behaviour |
| Rule-13.2 (Required) | The value of an expression and its persistent side-effects shall be the same under all permitted evaluation orders |
![]() | ||
| 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 |