Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      static_assert

      From cppreference.com
      <c‎ |error
       
       
      Error handling
      Error codes
      Error codes
      Assertions
      static_assert
      (C11)(removed in C23)
      Bounds checking
       
      Defined in header<assert.h>
      #define static_assert _Static_assert
      (since C11)
      (removed in C23)

      This convenience macro expands to the keyword_Static_assert.

      Contents

      [edit]Example

      Run this code
      #include <assert.h> int main(void){    static_assert(2+2==4,"2+2 isn't 4");// well-formed     static_assert(sizeof(int)<sizeof(char),// compile-time error"this program requires that int is less than char");}

      [edit]Notes

      Since C23,static_assert is itself a keyword, which may also be a predefined macro, so<assert.h> no longer provides it.

      [edit]References

      • C23 standard (ISO/IEC 9899:2024):
      • 7.2/3 Diagnostics <assert.h> (p: TBD)
      • C17 standard (ISO/IEC 9899:2018):
      • 7.2/3 Diagnostics <assert.h> (p: 135)
      • C11 standard (ISO/IEC 9899:2011):
      • 7.2/3 Diagnostics <assert.h> (p: 186)

      [edit]See also

      C++ documentation forStatic Assertion
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/error/static_assert&oldid=180039"

      [8]ページ先頭

      ©2009-2025 Movatter.jp