byzero1.C
.
Warning: do not divide by zero.
Attempts to perform
double
and
int
division by zero behave differently.
On
storm.cis.fordham.edu
,
a C++ program that attempts to perform
int
division by zero is assassinated by the operating system
with a little bullet called a
signal.
An assassinated program never lives long enough to return
EXIT_SUCCESS
.
jsmith@storm:~$ cd
jsmith@storm:~$ pwd
jsmith@storm:~$ wget https://markmeretzky.com/fordham/1600/src/division/byzero1.C
jsmith@storm:~$ ls -l (Make sure there is a new file named byzero1.C)
jsmith@storm:~$ c++ byzero1.C
byzero1.C: In function ‘int main()’:
byzero1.C:10:20: warning: division by zero
jsmith@storm:~$ ls -l (Make sure there is a new file named a.out)
jsmith@storm:~$ ./a.out
inf
The above quotient was infinity.
Floating point exception (core dumped)
jsmith@storm:~$ echo $?
136 (This number is not EXIT_SUCCESS. Subtract 128 to find out the cause of death.)
There are many types of signals, each with its own identifying number.
136 − 128 = 8.
Signal number 8 is
SIGFPE
,
the “floating point exception” signal.
It means that the C++ program was assassinated while attempting arithmetic.