Function Pointer Table in FLASH

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Function Pointer Table in FLASH

跳至解决方案
1,697 次查看
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

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,345 次查看
DustyStew
Contributor V

I seem to have worked it out

 

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

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,346 次查看
DustyStew
Contributor V

I seem to have worked it out

 

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

0 项奖励
回复
1,345 次查看
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