Function Pointer Table in FLASH

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Function Pointer Table in FLASH

Jump to solution
992 Views
DustyStew
Contributor V

I'm using Codewarrior 5.9.0, coding in C for the HC9S08AW32

 

In my program, I use a table of function pointers. The table is declared like this:

 

#pragma CONST_SEG DEFAULT

const void ((*functions[NUM_FUNCTIONS])(void)) = 

{

    function1,

    function2,

   function3

};

 

And the functions are called like this:

 

functions[i]();

 

This works fine but the function table is allocated into RAM. Can I get that table to be stored in FLASH?

 

THX

Labels (1)
Tags (1)
0 Kudos
1 Solution
640 Views
DustyStew
Contributor V

I seem to have worked it out

 

const void ((* const functions[])(void))

View solution in original post

0 Kudos
2 Replies
641 Views
DustyStew
Contributor V

I seem to have worked it out

 

const void ((* const functions[])(void))

0 Kudos
640 Views
CompilerGuru
NXP Employee
NXP Employee

Yes, exactly.

Probably the void's do not need to be const protected:

void ((* const functions[])(void))={....};

 

As always with C function pointers, it gets a lot more readable with a typedef:

 

typedef void (* FunctionPointers) (void);

const FunctionPointers functions[] = {...};

 

Daniel