![]() |
|
Rule 11.6.1 - Variables initialized via output-parameter? - 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++:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=188) +---- Forum: 4.11 Declarators (https://forum.misra.org.uk/forumdisplay.php?fid=197) +---- Thread: Rule 11.6.1 - Variables initialized via output-parameter? (/showthread.php?tid=1748) |
Rule 11.6.1 - Variables initialized via output-parameter? - cgpzs - 02-09-2025 Hi, Consider the following example: Code: // external_c_api.hHow would one apply 11.6.1 in this case? It's not possible to avoid the two-step initialization process. There may not even be a "sensible default" to give to `x` before giving it the "real" value (and MISRA explicitly discourages this pattern). In particular, doing "foo_t x{};" leads to zero initialization, but there is no enumerator with the value 0. Thanks! RE: Rule 11.6.1 - Variables initialized via output-parameter? - misra cpp - 19-09-2025 11.6.1 is only advisory for precisely this reason, there are cases when it its not possible to initialise to a 'sensible' state. Note that this rule only cares about variables being initialised, it doesn't care if the value is overwritten before being read, though another rule may fire on that. |