Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 11.6.1 - Variables initialized via output-parameter?
#1
Hi,

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!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)