Advertisement

is there a brighter way to check a variable if it's bit is set?...

Started by May 16, 2002 12:15 PM
13 comments, last by mickey 22 years, 6 months ago
Brilliant! That stores the 32 bit handle of the function in an array indexed by the flag!

good one Queasy
quote: Original post by pafcu
No, your code is not the same. In Case 1 you check if the parameter passed to the function is the number 1. This will not be the case if you have combined several flags. ACTIVATEA|ACTIVATEB=00000000000000000000000000000011b=3. The compiler can''t see that 3 is a combination of 1 and 2. You have to check the individual bits like Waverider did.


the compiler? anyway when you run the program, it will work, it will know what bits are set, try it

queasy:
i''ve never seen this kind of declaration yet?

void (*StateFn[NUM_OF_STATES])(); // what with the () at the end?

actually i''ve never seen a code like that ever, hope you could explain how did it happen, ie,

StateFn[flag](); // how could that automatically call the right function? and much weird is, that''s a variable ain''t it?

thanks,







Advertisement
quote: Original post by pafcu
No, your code is not the same. In Case 1 you check if the parameter passed to the function is the number 1. This will not be the case if you have combined several flags. ACTIVATEA|ACTIVATEB=00000000000000000000000000000011b=3. The compiler can''t see that 3 is a combination of 1 and 2. You have to check the individual bits like Waverider did.


the compiler? anyway when you run the program, it will work, it will know what bits are set, try it

queasy:
i''ve never seen this kind of declaration yet?

void (*StateFn[NUM_OF_STATES])(); // what with the () at the end?

actually i''ve never seen a code like that ever, hope you could explain how did it happen, ie,

StateFn[flag](); // how could that automatically call the right function? and much weird is, that''s a variable ain''t it?

thanks,







http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
For a nice tutorial about function pointers, function pointer tables (that''s what Queasy used) and functors, look here.

/ Yann
Queasy man great little tut. I''ve always done things similar to switch''s with 100''s of cases now that just makes my life better :D

Jeff D
Suffered seven plagues, but refused to let the slaves go free. ~ Ross Atherton

This topic is closed to new replies.

Advertisement