0

While going over infrastructure code, I found this:

return !!(fin.flags & FIN_ACCEPT);

Does this has a meaning other than two logical nots in succession?

dkb
  • 521
  • 5
  • 14

2 Answers2

4

! is logical negation. !! is logical negation applied twice.

It is typically used to normalise a boolean expression value to be either 0 or 1.

David Heffernan
  • 587,191
  • 41
  • 1,025
  • 1,442
1

It is used to turn a numerical value into a boolean value. For example:

a = 5;
a = !!a;

!(!a)---> !(!5) ----> !(0) ----> 1

a will have value 1.

Igor
  • 3,545
  • 1
  • 10
  • 32