02-09-2025, 11:26 AM
Hi,
Consider the following example:
How 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!
Consider the following example:
Code:
// external_c_api.h
enum error_t
{
// ...
};
enum foo_t
{
foo_A = 1,
foo_B = 2
};
error_t externalCApi(foo_t*);
// main.cpp
void f()
{
foo_t x;
error_t error = externalCApi(&x);
}
How 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!