What is the point in expression: !!var ?
Cedric Blancher
cedric.blancher at gmail.com
Tue Sep 13 20:10:25 UTC 2016
The point is to transform the value of a (any kind, like pointer) to a
Boolean value.
Ancient C trick, goes back to dmr
Ced
On 13 September 2016 at 21:54, twilight <pipfstarrd at openmailbox.org> wrote:
> Hello,
>
> I'm digging through FreeBSD cppcheck scan report with hope to catch some
> bugs.
>
> I've came along a line:
> c = cond(token, val, yylex(), noeval | !!a);
>
> What's the point in using !! twice? Can it be deleted?
> Here is the context:
>
> static arith_t cond(int token, union yystype *val, int op, int noeval)
> {
> arith_t a = or(token, val, op, noeval);
> arith_t b;
> arith_t c;
>
> if (last_token != ARITH_QMARK)
> return a;
>
> b = assignment(yylex(), noeval | !a);
>
> if (last_token != ARITH_COLON)
> yyerror("expecting ':'");
>
> token = yylex();
> *val = yylval;
>
> c = cond(token, val, yylex(), noeval | !!a);
>
> return a ? b : c;
> }
>
>
> --
> Cheers~
>
> PGP key fingerprint:
> 07B3 2177 3E27 BF41 DC65 CC95 BDA8 88F1 E9F9 CEEF
>
> You can retrieve my public key at pgp.mit.edu.
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
--
Cedric Blancher <cedric.blancher at gmail.com>
[https://plus.google.com/u/0/+CedricBlancher/]
Institute Pasteur
More information about the freebsd-hackers
mailing list