Function Pointer Table in FLASH

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Function Pointer Table in FLASH

ソリューションへジャンプ
1,707件の閲覧回数
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,355件の閲覧回数
DustyStew
Contributor V

I seem to have worked it out

 

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

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
1,356件の閲覧回数
DustyStew
Contributor V

I seem to have worked it out

 

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

0 件の賞賛
返信
1,355件の閲覧回数
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