Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

While the use of the runtime assertion is better than nothing, it needs to be placed in a function and executed, typically removed . This means that it is usually far away from the definition of the actual structure to which it refers. The diagnostic occurs only at runtime and only if the code path containing the assertion is executed.

...

The static_assert() macro accepts a constant expression e, which is evaluated as the first operand to the conditional operator. If e evaluates to nonzero, an array type with a dimension size of 1 is defined; otherwise, an array type with a dimension size of -1 is defined. Because it is invalid to declare an array with a negative dimensionsize, the resulting type definition will be flagged by the compiler. The name of the array is used to indicate the location of the failed assertion.

...