what's the two !! usage?

B

baumann.Pan

hi all,

in the linux kernel code compiler.h
i read
#define likely(x) __builtin_expect(!!(x), 1)

#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
#define __builtin_expect(exp,c) (exp)
#endif

what's the meaing of !!(x)?

thanks

baumann@pan
 
B

Ben Pfaff

what's the meaing of !!(x)?

It transforms any nonzero value to 1 and leaves zero unchanged.
It transforms null pointers to 0 and any nonnull pointer to 1.
It is equivalent to (x != 0).
 
P

Peter MacMillan

hi all,

in the linux kernel code compiler.h
i read
#define likely(x) __builtin_expect(!!(x), 1)

#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
#define __builtin_expect(exp,c) (exp)
#endif

what's the meaing of !!(x)?

thanks

baumann@pan

!! is "not not"

That is, x is an integer. if x is 0 then !x is 1. If x is not 0 then !x
is 0.

so say x is 42. !x is 0 and !!x is 1.

--
Peter MacMillan
e-mail/msn: (e-mail address removed)
icq: 1-874-927

GCS/IT/L d-(-)>-pu s():(-) a- C+++(++++)>$ UL>$ P++ L+ E-(-) W++(+++)>$
N o w++>$ O !M- V PS PE Y+ t++ 5 X R* tv- b++(+) DI D+(++)>$ G e++ h r--
y(--)
 
R

Richard Bos

Peter MacMillan said:
!! is "not not"

That is, x is an integer.

A scalar, rather. It works for pointers and floating point numbers as
well as for integers.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top