Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
799 views
in Technique[技术] by (71.8m points)

gcc - Embedded C - Too many arguments to function (pointer)

I am trying to invoke the following macro in my .cpp file:

#define IAP_ROM_LOCATION                0x1FFF1FF1UL
#define IAP_EXECUTE_CMD(a, b)           ((void (*)())(IAP_ROM_LOCATION))(a, b)

However, when I call said function like so:

IAP_EXECUTE_CMD(0, 0);

I get an error saying too many arguments specified? How is this? I would appreciate any pointers.

Development environment is GCC for Cortex-M3.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For readability, define a signature for the function to be called:

typedef void signature_t(int, int);

Then you can cast your ROM location

#define IAP_EXECUTE_CMD(a, b)  ((signature_t*)IAP_ROM_LOCATION) ((a),(b))

and with a recent GCC (current version of GCC is 4.6) I would make that an inline function

static inline void iap_execute_cmd(int a, int b) {
    ((signature_t*)IAP_ROM_LOCATION) ((a),(b));
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...