Skip to main content
GameDev.net gamedev.net
🔒 Locked

Strange operator

Started by Teric Jun 7, 2002 at 1:08 PM 5 replies 200+ views
Original Post
Teric
Teric
I was reading some code on a website, and I came across a strange operator: int a=!! (b+c) Has anyone seen this !! operator before? Is it simply a double ''not'' operator? How does it work? Let''s assume that b is 5 and c is 11, what would a be in the expression above? Thanks in advance!
I am always open to feedback, positive or negative...
Chem0sh
Chem0sh
Hmmm...never seen that before. If it is just a double negation, they would just cancel each other out.

My best guess, it''s a typo.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
IndirectX
IndirectX
It''s a double negation, except it evaluates to true or false. So for 5 and 6, the result will be true or 1 if converted to an integer.
---visit #directxdev on afternet <- not just for directx, despite the name
Teric
Teric
Thanks for the quick responses!
I am always open to feedback, positive or negative...
cgoat
cgoat
Another way to do the same thing (helps to understand what''s happening):


int a = (b+c)?1:0;


So if b+c is 0, "a" gets 0, otherwise "a" gets set to 1.
Chem0sh
Chem0sh
Hmm...I think that''s the first time I''ve actually seen the ternary operator actually make something easier to understand.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.