C++ assert

2021. 3. 12. 17:33·C++/Library

assert

  • <cassert> 라이브러리

assert

  • Debug 모드에서만 런타임에 작동한다.

    • VS의 전처리기 설정에 매크로가 설정되어있다.

      • Debug 모드에서는 _DEBUG

      • Release 모드에서는 NDEBUG

  • 내부 조건이 거짓이면 Debug Error를 발생시킨다.

      #include <cassert>
    
      int     main()
      {
        assert(false);
      }
  • 최대한 나눠서 쓰는게 디버깅하기에 좋다.

  • static assert

  • 컴파일 타임에 작동한다.

  • Release 모드에서도 작동한다.

  • 에러 문구를 넣어야 한다.

      #include <cassert>
    
      int     main()
    {
        const int x = 5;
        //const int x = 4;  // 컴파일 안됨
    
        static_assert(x == 5, "x should be 5");
      }
  • 릴리즈 모드에선 작동되지 않는다면, 차라리 예외처리를 전부 하는게 맞는 것 아닌가 생각했다.

  • 관련 참고 내용

    • KLDP 토론 스레드

    • assert 설명

저작자표시

'C++ > Library' 카테고리의 다른 글

C++ initializer_list  (0) 2021.03.19
C++ chrono  (0) 2021.03.16
C++ vector  (0) 2021.03.12
C++ tuple  (0) 2021.03.12
C++ array  (0) 2021.03.11
'C++/Library' 카테고리의 다른 글
  • C++ initializer_list
  • C++ chrono
  • C++ vector
  • C++ tuple
Caniro
Caniro
  • Caniro
    Minimalism
    Caniro
  • 전체
    오늘
    어제
    • 분류 전체보기 (316)
      • Algorithm (13)
        • 알기 쉬운 알고리즘 (10)
        • Search (1)
        • Sort (2)
      • Arduino (0)
      • C++ (185)
        • Class (46)
        • Exception (6)
        • Library (51)
        • Overloading (10)
        • SmartPointer (5)
        • Syntax (33)
        • TBC++ (23)
        • Templates (9)
        • VisualStudio (2)
      • Embedded (1)
      • Git (4)
      • Java (5)
      • Linux (16)
        • Error (1)
        • Linux Structure (11)
      • MacOS (7)
      • OS (1)
        • Concurrency (1)
      • Python (21)
        • Class (1)
        • Function (2)
        • Syntax (17)
      • Raspberrypi (9)
      • Review (1)
      • Utility (12)
        • VSCode (5)
        • VirtualBox (3)
      • Web (8)
        • Nginx (1)
        • React (3)
        • Django (1)
      • Windows (19)
        • Registry (3)
        • WSL (1)
        • DeviceDriver (6)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    SFC
    윈도우 명령어
    알림
    제외
    로지텍 마우스 제스처
    Solaris 10
    KakaoTalk
    SunOS 5.1
    windows
    java
    spring
    그림판
    MacOS
    맥북 카카오톡 알림 안뜸
    스프링 프레임워크 핵심 기술
    Windows 11
    Workspace
    백기선
    citrix workspace
    윈도우
    시스템 복구
    unix
    dism
    스프링
    mspaint
    EXCLUDE
    vscode
    logi options
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
Caniro
C++ assert
상단으로

티스토리툴바