Brilliant! That stores the 32 bit handle of the function in an array indexed by the flag!
good one Queasy
is there a brighter way to check a variable if it's bit is set?...
May 18, 2002 08:47 AM
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,
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
/ Yann
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement