Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does if (!msize) mean?

Tags:

c

I am trying to figure out the meaning of the following codes.

In here if (!msize) checking to see if msize is zero or if msize is NULL ?

if (!msize)
    msize = 1 / msize; /* provoke a signal */

//Example 1: A division-by-zero misuse, in lib/mpi/mpi-pow.c of the Linux kernel, where the entire code will be optimized away. 
//Compilers, GCC 4.7 and Clang 3.1
like image 561
new_user Avatar asked Feb 22 '14 14:02

new_user


3 Answers

if (msize == 0)
    msize = 1 / msize; /* provoke a signal */

It's checking if msize is 0, and is equivalent to writing if (msize == 0). If it is, it deliberately performs a divide by zero.

like image 146
John Kugelman Avatar answered Oct 05 '22 05:10

John Kugelman


if(!msize) is simply opposite of if(msize) here if(!msize) this expression becomes true if msize==0 or NULL...

like image 44
navin Avatar answered Oct 05 '22 06:10

navin


It means "If msize is EQUAL to 0". Remember that NOT in this instance is a logical operator. Also NULL is a standard MACRO in C.

However if msize is a boolean, then "if (!msize)" is equivalent to "if (msize == false)".

On a side note:-

5.6 Multiplicative operators

4) The binary / operator yields the quotient, and the binary % operator yields the remainder from the division of the first expression by the second. If the second operand of / or % is zero the behavior is undefined; otherwise (a/b)*b + a%b is equal to a. If both operands are nonnegative then the remainder is nonnegative; if not, the sign of the remainder is implementation-defined79). (emphasis mine)


Also you may get the result as 1.#IND000 which is basically the representation of NaN, basically IND is the representation of NaN ( Not a Number ) in Windows system. IND stands for "indeterminate form", mostly result from illegal operation like divided by zero.

like image 36
Rahul Tripathi Avatar answered Oct 05 '22 06:10

Rahul Tripathi