J
jon wayne
Hi
Am trying to replace the classic switch case construct (am workng on
a telecom stack devlpmnt)with an array of function ptrs.
The problm am facing is that of indexing. - the case vals can be
any of 0- 0xFF(1 byte long) - but unfortunately as of now I just need
to use about 15 of 'em.
In the sense I can't just make an array of function ptrs - coz the
case vals I need to use right now are high up in the range.
My soln was somethng like this
enumSomeError (*fn[])() = {NULL,NULL,... ,
decodeParamOne,NULL,...//etc};
....
// get rid of the switch
if (fn[getParamType])
fn[getParamType()};// etc
PROBLEM - since I've very few functions to be actually invoked in
the whole range, the array of function occupies quite a bit of memory -
most of which has null pointers.
Isn't there a better soln? ( I don't really want to use a Map or
any other built in c++ container)
Next , Is there really much of a performance diff betn function
pointers & switch?
Also - is the above a bad practice?? Experienced coders at my firm
say it's not a good design to use function pointers.
thanks a lot for your comments & help
Am trying to replace the classic switch case construct (am workng on
a telecom stack devlpmnt)with an array of function ptrs.
The problm am facing is that of indexing. - the case vals can be
any of 0- 0xFF(1 byte long) - but unfortunately as of now I just need
to use about 15 of 'em.
In the sense I can't just make an array of function ptrs - coz the
case vals I need to use right now are high up in the range.
My soln was somethng like this
enumSomeError (*fn[])() = {NULL,NULL,... ,
decodeParamOne,NULL,...//etc};
....
// get rid of the switch
if (fn[getParamType])
fn[getParamType()};// etc
PROBLEM - since I've very few functions to be actually invoked in
the whole range, the array of function occupies quite a bit of memory -
most of which has null pointers.
Isn't there a better soln? ( I don't really want to use a Map or
any other built in c++ container)
Next , Is there really much of a performance diff betn function
pointers & switch?
Also - is the above a bad practice?? Experienced coders at my firm
say it's not a good design to use function pointers.
thanks a lot for your comments & help