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
  • 551
  • 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
  • 601,492
  • 42
  • 1,072
  • 1,490
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 Pejic
  • 3,658
  • 1
  • 14
  • 32