통합검색
· 마을서비스란?  · 포럼마을  · 일반마을  · 테마마을  · 마을랭킹  · 활동왕
· 덱스퍼트란?  · TECBOX   · PRSBOX   · 이용안내  
· DEXT제품군  · 솔루션베이  · S/W & ESD 컴포넌트
· 프로그램베이
· LiveSeminar  · LiveConference
Visual C++ 포럼마을 입니다.
  마을등급 Visual C++   이 마을은 포럼마을 입니다이 마을은 자유가입제 마을 입니다 마을소개 페이지로 이동 전입신청
마을촌장촌장 나성훈 주민 34033 since 2006-12-29
우리마을 공지사항
질문&답변
강좌&팁
자유게시판
자료실
앨범
개인게시판
마을 게시판
등록된 마을 게시판이
없습니다.
랑데브 게시판
칼럼 게시판
개발자 고충상담
Dev Talk
자유토론방
벼룩시장
재나미 우스개
구인/프로젝트 정보
사람인 채용 게시판
  고객지원 게시판
마이 데브피아
 나의 e-Money 내역
 활동왕 My Page
 스크랩한 게시글보기
 쪽지관리
 주소록관리

 질문&답변 ※ 꼭 답변채택을 해주시어 성의껏 답변해주신 회원님께 감사의 마음을 전하시길 바랍니다.
 0 으로 나누기 했을때 크래시가 안나는 문제  | VC++ 일반 2020-01-21 오전 10:50:13
QKing 번호: 977493 추천:0  / 읽음:112

비쥬얼 스튜디오를 사용중이고

제가아는 상식선에서 0 으로 나눗셈을 하면 프로그램이 종료되는걸로 알고있습니다.

 

그런데 종료가 안되고(죽지않고) 그냥 살아있네요....

 

다만 0 으로 나누기를 했던 코드 다음은 실행이 되지 않는것 같습니다( 로그를 찍어본 결과.. )

 

강제 크래시 테스트는

 

 int nDivide = 0;

 int nMok = 0;

 nMok = 2300 % nDivide;
 nMok = 2300 / nDivide;

 

대략 이런 코드로 진행해보았구여

 

전 크래시가 나기를 바라는데 뭐가 문제일까여?

 

프로그램은 mfc 에 다이알로그 베이스 입니다.

이 글에 답변 등록하기
[채택답변] 참고해보세요.
0
2020-01-21 오후 1:28:35
질문자 인사 : 답변 감사합니다^^
최종 의도는 크래시로 죽을때 덤프파일이 생성되게 하려고 한것인데
죽지를 않아서 방법이 없네요...
좋은 답변 감사드립니다~
  칡흙 번호: 977494  
 

// assert ( ) 로 확인 가능 ㅇ_ㅇ;;

 

 

C++ code - 24 lines - codepad
http://codepad.org/57EDP4z0


#include <assert.h>

#include <iostream>

 

using namespace std;

 

int division(int a, int b) {

    if (b==0) {

        cerr << "Error at line " << __LINE__ << " in file " << __FILE__ << endl;

    }

   assert(b!=0);

   return (a/b);

}

 

int main () {

   int x = 11;

   int y = 0;

   int z;

 

   z = division(x, y);

    

   cout << "Answer is " << z << endl;

 

   return 0;

}

 

Error at line 9 in file t.cpp

t: t.cpp:11: int division(int, int): Assertion `b!=0' failed.

 

Disallowed system call: SYS_kill



 

//

https://www.onlinegdb.com/

https://cs.baylor.edu/~donahoo/tools/gdb/tutorial.html

https://stackoverflow.com/questions/589653/switching-to-assembly-in-gdb



 

//

gdb 온라인 테스트 결과

b 19                  // 19 번째 줄 break

debug 버튼 실행

layout asm           //어셈블리로 보기

 

   0x4004f6 <main()>       push   %rbp                                        
   0x4004f7 <main()+1>     mov    %rsp,%rbp                                   
   0x4004fa <main()+4>     movl   $0x0,-0x8(%rbp)                             
   0x400501 <main()+11>    movl   $0x0,-0x4(%rbp)                             
   0x400508 <main()+18>    mov    $0x8fc,%eax                                 
   0x40050d <main()+23>    cltd                                               
   0x40050e <main()+24>    idivl  -0x8(%rbp)                                  
   0x400511 <main()+27>    mov    %edx,-0x4(%rbp)                             
b+ 0x400514 <main()+30>    mov    $0x8fc,%eax                                 
   0x400519 <main()+35>    cltd                                               
   0x40051a <main()+36>    idivl  -0x8(%rbp)                                  
   0x40051d <main()+39>    mov    %eax,-0x4(%rbp)                             
    0x400520 <main()+42>    mov    $0x0,%eax                                    
    0x400525 <main()+47>    pop    %rbp                                         
    0x400526 <main()+48>    retq                                                
rax   40050d <main()+23>    cltd           >  


 

 

 

//  ㅇ_ㅇ;; 웹 버전도 오류 없이 실행 되네요.


http://codepad.org/Zg6xRZL6

 

#include <stdio.h>

 

int main()

{

 

 int nDivide = 0;

 

 int nMok = 0;

 

 nMok = 2300 % nDivide;

 nMok = 2300 / nDivide;

    return 0;

}

 

 

 

//


C++ 오류 발생시 원인 정리 · Elky Essay
http://elky84.github.io/2010/03/16/case_by_exception_in_cpp/

개발자 이야기 :: double형을 0으로 나눌 때
http://devfun.tistory.com/2

C++ zero divide - Bing
http://www.bing.com/search?q=C%2B%2B+zero+divide&qs=n&form=QBRE&sp=-1&pq=c%2B%2B+zero+divide&sc=0-15&sk=&cvid=BDB0FF48AC7940E7B4394F111E6F8811

Division in C++ not working as expected - Stack Overflow
http://stackoverflow.com/questions/6101084/division-in-c-not-working-as-expected

c++ - Catching exception: divide by zero - Stack Overflow
http://stackoverflow.com/questions/6121623/catching-exception-divide-by-zero

Handling the Divide by Zero Exception in C++ - GeeksforGeeks
http://www.geeksforgeeks.org/handling-the-divide-by-zero-exception-in-c/

DivideByZeroException 클래스 (System) | Microsoft Docs
http://docs.microsoft.com/ko-kr/dotnet/api/system.dividebyzeroexception?view=netframework-4.8

How to avoid dividing by zero? - C++ Forum
http://www.cplusplus.com/forum/beginner/50428/

[VS2010] C/C++ : Integer division by zero.
http://great-artist.tistory.com/62

c++ zero divide - Google 검색
http://www.google.com/search?source=hp&ei=G10mXoGRFZL1hwPxrrywDA&q=c%2B%2B+zero+divide&oq=c%2B%2B+zero+divide&gs_l=psy-ab.3..0j0i8i30l9.822.8737..9008...0.0..0.128.1628.2j13......0....1..gws-wiz.......0i10j0i131j0i13j0i7i30j0i8i7i30.MLQN44v20EA&ved=0ahUKEwjBisqRzpPnAhWS-mEKHXEXD8YQ4dUDCAY&uact=5

divide by zero - c++ division by 0 - Stack Overflow
http://stackoverflow.com/questions/4745311/c-division-by-0

C++ divide by zero - Stack Overflow
http://stackoverflow.com/questions/15277129/c-divide-by-zero

divide by zero exception - C++ Forum
http://www.cplusplus.com/forum/beginner/186794/

Division by Zero
http://www.viva64.com/en/t/0085/

C++ - Integer division by zero | c++ Tutorial
http://riptutorial.com/cplusplus/example/7411/integer-division-by-zero

How to Capture the Integer-Divide-By-Zero Error in C++? | Technology of Computing
http://helloacm.com/how-to-capture-the-integer-divide-by-zero-error-in-c/

[Java] Divide by Zero 예외는 항상 발생할까? | MSFL :: 모리스 소프트웨어 공작소
http://ccambo.blogspot.com/2017/04/java-divide-by-zero.html

What happens if we divide by 0 in C++? - Quora
http://www.quora.com/What-happens-if-we-divide-by-0-in-C

C++ by Example - Steve Donovan - Google 도서
http://books.google.co.kr/books?id=6v26YoBgeLsC&pg=PA99&lpg=PA99&dq=c%2B%2B+zero+divide&source=bl&ots=JqZoPBFb_6&sig=ACfU3U2W00k9QvP1ENs0W6Xtzl3oAm9ikQ&hl=ko&sa=X&ved=2ahUKEwikkpiWzpPnAhUw7GEKHVN3CF0Q6AEwCnoECBQQAQ#v=onepage&q=c%2B%2B%20zero%20divide&f=false

c++ - Prompting for two integers and dividing, using exceptions to handle divide-by-zero errors - Code Review Stack Exchange
http://codereview.stackexchange.com/questions/155164/prompting-for-two-integers-and-dividing-using-exceptions-to-handle-divide-by-ze

What does 0 divided by 0 result in on a CPU? - Quora
http://www.quora.com/What-does-0-divided-by-0-result-in-on-a-CPU

How to catch a divide by zero error in C++?
http://www.tutorialspoint.com/how-to-catch-a-divide-by-zero-error-in-cplusplus

Assertion Divide by Zero Example, C++ (clang) - rextester
http://rextester.com/PYI81141

Detect division by zero - Rosetta Code
http://rosettacode.org/wiki/Detect_division_by_zero

Lecture Slides for Programming in C++ (Version 2019-02-04): The C++ Language ... - Michael D. Adams - Google 도서
http://books.google.co.kr/books?id=1rmIDwAAQBAJ&pg=PA2062&lpg=PA2062&dq=c%2B%2B+zero+divide&source=bl&ots=RsRJ5uEt3-&sig=ACfU3U0JAcLyWtj4lNq0M2-DM94d06nOBQ&hl=ko&sa=X&ved=2ahUKEwikkpiWzpPnAhUw7GEKHVN3CF0Q6AEwEHoECBMQAQ#v=onepage&q=c%2B%2B%20zero%20divide&f=false

Solved: C++ 12.5 Program: Divide By Zero This Program Will... | Chegg.com
http://www.chegg.com/homework-help/questions-and-answers/c-125-program-divide-zero-program-test-exception-handling-division-user-enter-2-numbers-at-q16890379

 

 [답변]참고해보세요. 2020-01-21 오전 10:55:36
칡흙 번호: 977494 추천:0  
 

// assert ( ) 로 확인 가능 ㅇ_ㅇ;;

 

 

C++ code - 24 lines - codepad
http://codepad.org/57EDP4z0


#include <assert.h>

#include <iostream>

 

using namespace std;

 

int division(int a, int b) {

    if (b==0) {

        cerr << "Error at line " << __LINE__ << " in file " << __FILE__ << endl;

    }

   assert(b!=0);

   return (a/b);

}

 

int main () {

   int x = 11;

   int y = 0;

   int z;

 

   z = division(x, y);

    

   cout << "Answer is " << z << endl;

 

   return 0;

}

 

Error at line 9 in file t.cpp

t: t.cpp:11: int division(int, int): Assertion `b!=0' failed.

 

Disallowed system call: SYS_kill



 

//

https://www.onlinegdb.com/

https://cs.baylor.edu/~donahoo/tools/gdb/tutorial.html

https://stackoverflow.com/questions/589653/switching-to-assembly-in-gdb



 

//

gdb 온라인 테스트 결과

b 19                  // 19 번째 줄 break

debug 버튼 실행

layout asm           //어셈블리로 보기

 

   0x4004f6 <main()>       push   %rbp                                        
   0x4004f7 <main()+1>     mov    %rsp,%rbp                                   
   0x4004fa <main()+4>     movl   $0x0,-0x8(%rbp)                             
   0x400501 <main()+11>    movl   $0x0,-0x4(%rbp)                             
   0x400508 <main()+18>    mov    $0x8fc,%eax                                 
   0x40050d <main()+23>    cltd                                               
   0x40050e <main()+24>    idivl  -0x8(%rbp)                                  
   0x400511 <main()+27>    mov    %edx,-0x4(%rbp)                             
b+ 0x400514 <main()+30>    mov    $0x8fc,%eax                                 
   0x400519 <main()+35>    cltd                                               
   0x40051a <main()+36>    idivl  -0x8(%rbp)                                  
   0x40051d <main()+39>    mov    %eax,-0x4(%rbp)                             
    0x400520 <main()+42>    mov    $0x0,%eax                                    
    0x400525 <main()+47>    pop    %rbp                                         
    0x400526 <main()+48>    retq                                                
rax   40050d <main()+23>    cltd           >  


 

 

 

//  ㅇ_ㅇ;; 웹 버전도 오류 없이 실행 되네요.


http://codepad.org/Zg6xRZL6

 

#include <stdio.h>

 

int main()

{

 

 int nDivide = 0;

 

 int nMok = 0;

 

 nMok = 2300 % nDivide;

 nMok = 2300 / nDivide;

    return 0;

}

 

 

 

//


C++ 오류 발생시 원인 정리 · Elky Essay
http://elky84.github.io/2010/03/16/case_by_exception_in_cpp/

개발자 이야기 :: double형을 0으로 나눌 때
http://devfun.tistory.com/2

C++ zero divide - Bing
http://www.bing.com/search?q=C%2B%2B+zero+divide&qs=n&form=QBRE&sp=-1&pq=c%2B%2B+zero+divide&sc=0-15&sk=&cvid=BDB0FF48AC7940E7B4394F111E6F8811

Division in C++ not working as expected - Stack Overflow
http://stackoverflow.com/questions/6101084/division-in-c-not-working-as-expected

c++ - Catching exception: divide by zero - Stack Overflow
http://stackoverflow.com/questions/6121623/catching-exception-divide-by-zero

Handling the Divide by Zero Exception in C++ - GeeksforGeeks
http://www.geeksforgeeks.org/handling-the-divide-by-zero-exception-in-c/

DivideByZeroException 클래스 (System) | Microsoft Docs
http://docs.microsoft.com/ko-kr/dotnet/api/system.dividebyzeroexception?view=netframework-4.8

How to avoid dividing by zero? - C++ Forum
http://www.cplusplus.com/forum/beginner/50428/

[VS2010] C/C++ : Integer division by zero.
http://great-artist.tistory.com/62

c++ zero divide - Google 검색
http://www.google.com/search?source=hp&ei=G10mXoGRFZL1hwPxrrywDA&q=c%2B%2B+zero+divide&oq=c%2B%2B+zero+divide&gs_l=psy-ab.3..0j0i8i30l9.822.8737..9008...0.0..0.128.1628.2j13......0....1..gws-wiz.......0i10j0i131j0i13j0i7i30j0i8i7i30.MLQN44v20EA&ved=0ahUKEwjBisqRzpPnAhWS-mEKHXEXD8YQ4dUDCAY&uact=5

divide by zero - c++ division by 0 - Stack Overflow
http://stackoverflow.com/questions/4745311/c-division-by-0

C++ divide by zero - Stack Overflow
http://stackoverflow.com/questions/15277129/c-divide-by-zero

divide by zero exception - C++ Forum
http://www.cplusplus.com/forum/beginner/186794/

Division by Zero
http://www.viva64.com/en/t/0085/

C++ - Integer division by zero | c++ Tutorial
http://riptutorial.com/cplusplus/example/7411/integer-division-by-zero

How to Capture the Integer-Divide-By-Zero Error in C++? | Technology of Computing
http://helloacm.com/how-to-capture-the-integer-divide-by-zero-error-in-c/

[Java] Divide by Zero 예외는 항상 발생할까? | MSFL :: 모리스 소프트웨어 공작소
http://ccambo.blogspot.com/2017/04/java-divide-by-zero.html

What happens if we divide by 0 in C++? - Quora
http://www.quora.com/What-happens-if-we-divide-by-0-in-C

C++ by Example - Steve Donovan - Google 도서
http://books.google.co.kr/books?id=6v26YoBgeLsC&pg=PA99&lpg=PA99&dq=c%2B%2B+zero+divide&source=bl&ots=JqZoPBFb_6&sig=ACfU3U2W00k9QvP1ENs0W6Xtzl3oAm9ikQ&hl=ko&sa=X&ved=2ahUKEwikkpiWzpPnAhUw7GEKHVN3CF0Q6AEwCnoECBQQAQ#v=onepage&q=c%2B%2B%20zero%20divide&f=false

c++ - Prompting for two integers and dividing, using exceptions to handle divide-by-zero errors - Code Review Stack Exchange
http://codereview.stackexchange.com/questions/155164/prompting-for-two-integers-and-dividing-using-exceptions-to-handle-divide-by-ze

What does 0 divided by 0 result in on a CPU? - Quora
http://www.quora.com/What-does-0-divided-by-0-result-in-on-a-CPU

How to catch a divide by zero error in C++?
http://www.tutorialspoint.com/how-to-catch-a-divide-by-zero-error-in-cplusplus

Assertion Divide by Zero Example, C++ (clang) - rextester
http://rextester.com/PYI81141

Detect division by zero - Rosetta Code
http://rosettacode.org/wiki/Detect_division_by_zero

Lecture Slides for Programming in C++ (Version 2019-02-04): The C++ Language ... - Michael D. Adams - Google 도서
http://books.google.co.kr/books?id=1rmIDwAAQBAJ&pg=PA2062&lpg=PA2062&dq=c%2B%2B+zero+divide&source=bl&ots=RsRJ5uEt3-&sig=ACfU3U0JAcLyWtj4lNq0M2-DM94d06nOBQ&hl=ko&sa=X&ved=2ahUKEwikkpiWzpPnAhUw7GEKHVN3CF0Q6AEwEHoECBMQAQ#v=onepage&q=c%2B%2B%20zero%20divide&f=false

Solved: C++ 12.5 Program: Divide By Zero This Program Will... | Chegg.com
http://www.chegg.com/homework-help/questions-and-answers/c-125-program-divide-zero-program-test-exception-handling-division-user-enter-2-numbers-at-q16890379

 

이 글에 답변 등록하기
목록 보기   지금 보고 계시는 글을 회원님의 my Mblog >> 스크랩에 넣어두고 다음에 바로 보실 수 있습니다.  
회사소개  |   개인정보취급방침  |  제휴문의  |   광고문의  |   E-Mail 무단수집거부  |   고객지원  |   이용안내  |   세금계산서
사업자등록번호 안내: 220-81-90008 / 통신판매업신고번호 제 2017-서울구로-0055호 / 대표: 홍영준, 서민호
08390, 서울시 구로구 디지털로32길 30, 1211호 / TEL. 02_6719_6200 / FAX. 02-6499-1910
Copyright ⓒ (주) 데브피아. All rights reserved.