Rule 3-4-1 issues - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19) +---- Forum: 6.3 Basic concepts (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=132) +---- Thread: Rule 3-4-1 issues (/showthread.php?tid=1122) |
Rule 3-4-1 issues - CGeddes - 16-10-2014 We're having issues complying with rule 3-4-1 in a number of functions that initialise a temporary variable which is subsequently modified and tested within a loop. I appreciate in many cases this can be resolved with recursion, however, it seems an excessive solution given the additional considerations required. The only other solution we've found (that doesn't conflict with other rules) is to declare and initialise a struct with the members set to the required values. e.g. Code: void f (void) Re: Rule 3-4-1 issues - misra cpp - 11-10-2016 This program is equivalent and compliant. Result has to be declared outside the loop, as the value in loop n+1 depends upon the value in loop n, so Result cannot be inside the body of the loop Code: void f ( void ) |