小编S1i*_*ery的帖子

函数指针参数被忽略/不需要

我目前正在为微处理器编写 C 代码,我遇到了一些我无法解释的事情。我已经使用函数指针实现了命令行界面。为此,我创建了一个结构体,其中包含命令的名称、指向要运行的函数的指针以及帮助说明。

typedef void(*command)(char *);
typedef struct commandStruct {
    char const *name;
    command execute;
    char const *help;
} commandStruct;

const commandStruct commands[] =
{
    {"led", CmdLed, "Turns on or off the LED1"},
    {"AT+START_SIM", start_simulation, "Starts the simulation"},
    {"AT+STOP_SIM", stop_simulation, "Stops the simulation"},
    {"",0,""} //End of table indicator.
};

void exec_command(char *buffer)
{
    uint16 i = 0;
    char *cmd = buffer;
    char *args;
    while (buffer[i])
    {
        if(buffer[i] == '=')
        {
            buffer[i] = 0;
            args = buffer + i + 1; …
Run Code Online (Sandbox Code Playgroud)

c function-pointers

5
推荐指数
1
解决办法
990
查看次数

标签 统计

c ×1

function-pointers ×1