NevermindZZT / cpost

c语言程序上下文切换和解耦的工具
MIT License
272 stars 97 forks source link

ceventRun编译提示cevent.c(114): error: too many arguments to function call, expected 0, have 1怎么处理呢,只能识别不传参的函数 #13

Open WLiangJun opened 6 months ago

WLiangJun commented 6 months ago

老师,请教一下,ceventRun编译提示cevent.c(114): error: too many arguments to function call, expected 0, have 1怎么处理呢,只能识别不传参的函数,怎么解决呢。需要根据自己的函数情况做适配吗?能不能帮忙分析解决一下,谢谢 image

NevermindZZT commented 6 months ago

用的是最新的 keil 吧 之前这里传参,使用的函数类型是一个不带参数的函数,原先的 C 对这个类型的函数,可以传递任意的参数数量进去,但是最新的 C 规范已经不允许这种行为了,需要明确定义函数的类型,后面我会更新一版,你可以按照下面的方式自己修改使用

static void ceventRun(CEvent *cevent)
{
    if (cevent->paramNum < 1)
    {
        return;
    }
    switch (cevent->paramNum)
    {
    case 1:
        void (*function)() = (void (*)())(cevent->param[0]);
        function();
        break;
    case 2:
        void (*function)(void *) = (void (*)())(cevent->param[0]);
        function(cevent->param[1]);
        break;
    case 3:
        void (*function)(void *, void *) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2]);
        break;
    case 4:
        void (*function)(void *, void *, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3]);
        break;
    case 5:
        void (*function)(void *, void *, void*, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3], cevent->param[4]);
        break;
    case 6:
        void (*function)(void *, void *, void*, void*, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3], cevent->param[4],
                 cevent->param[5]);
        break;
    case 7:
        void (*function)(void *, void *, void*, void*, void*, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3], cevent->param[4],
                 cevent->param[5], cevent->param[6]);
        break;
    case 8:
        void (*function)(void *, void *, void*, void*, void*, void*, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3], cevent->param[4],
                 cevent->param[5], cevent->param[6], cevent->param[7]);
        break;
    default:
        break;
    }
}
WLiangJun commented 6 months ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

WLiangJun commented 6 months ago

用的是最新的 keil 吧 之前这里传参,使用的函数类型是一个不带参数的函数,原先的 C 对这个类型的函数,可以传递任意的参数数量进去,但是最新的 C 规范已经不允许这种行为了,需要明确定义函数的类型,后面我会更新一版,你可以按照下面的方式自己修改使用

static void ceventRun(CEvent *cevent)
{
    if (cevent->paramNum < 1)
    {
        return;
    }
    switch (cevent->paramNum)
    {
    case 1:
        void (*function)() = (void (*)())(cevent->param[0]);
        function();
        break;
    case 2:
        void (*function)(void *) = (void (*)())(cevent->param[0]);
        function(cevent->param[1]);
        break;
    case 3:
        void (*function)(void *, void *) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2]);
        break;
    case 4:
        void (*function)(void *, void *, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3]);
        break;
    case 5:
        void (*function)(void *, void *, void*, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3], cevent->param[4]);
        break;
    case 6:
        void (*function)(void *, void *, void*, void*, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3], cevent->param[4],
                 cevent->param[5]);
        break;
    case 7:
        void (*function)(void *, void *, void*, void*, void*, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3], cevent->param[4],
                 cevent->param[5], cevent->param[6]);
        break;
    case 8:
        void (*function)(void *, void *, void*, void*, void*, void*, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3], cevent->param[4],
                 cevent->param[5], cevent->param[6], cevent->param[7]);
        break;
    default:
        break;
    }
}

好滴,明白了谢谢大大。还有一个问题,就是使用cevent的时候,对event的请求数量和导出事件数量有限制吗?我看了一下好像没有说性能。有个地方提了一下事件缓存,这个事件缓存指导出的事件函数个数还是ceventpost的请求数呢?谢谢答疑

NevermindZZT commented 6 months ago

用的是最新的 keil 吧 之前这里传参,使用的函数类型是一个不带参数的函数,原先的 C 对这个类型的函数,可以传递任意的参数数量进去,但是最新的 C 规范已经不允许这种行为了,需要明确定义函数的类型,后面我会更新一版,你可以按照下面的方式自己修改使用

static void ceventRun(CEvent *cevent)
{
    if (cevent->paramNum < 1)
    {
        return;
    }
    switch (cevent->paramNum)
    {
    case 1:
        void (*function)() = (void (*)())(cevent->param[0]);
        function();
        break;
    case 2:
        void (*function)(void *) = (void (*)())(cevent->param[0]);
        function(cevent->param[1]);
        break;
    case 3:
        void (*function)(void *, void *) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2]);
        break;
    case 4:
        void (*function)(void *, void *, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3]);
        break;
    case 5:
        void (*function)(void *, void *, void*, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3], cevent->param[4]);
        break;
    case 6:
        void (*function)(void *, void *, void*, void*, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3], cevent->param[4],
                 cevent->param[5]);
        break;
    case 7:
        void (*function)(void *, void *, void*, void*, void*, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3], cevent->param[4],
                 cevent->param[5], cevent->param[6]);
        break;
    case 8:
        void (*function)(void *, void *, void*, void*, void*, void*, void*) = (void (*)())(cevent->param[0]);
        function(cevent->param[1], cevent->param[2], cevent->param[3], cevent->param[4],
                 cevent->param[5], cevent->param[6], cevent->param[7]);
        break;
    default:
        break;
    }
}

好滴,明白了谢谢大大。还有一个问题,就是使用cevent的时候,对event的请求数量和导出事件数量有限制吗?我看了一下好像没有说性能。有个地方提了一下事件缓存,这个事件缓存指导出的事件函数个数还是ceventpost的请求数呢?谢谢答疑

有个缓存的配置,主要是用来做效率提升的,属于用内存空间换速度,如果开了,就需要注意那个大小配置 大小计算方式注释有写,如果配置小了会发生异常

WLiangJun commented 6 months ago

好的,谢谢大大

WLiangJun commented 6 months ago

大大,我的编译环境要这样才不会报错,贴出来给大家参考: static void ceventRun(CEvent cevent) { if (cevent->paramNum < 1) { return; } void (function)() = (void ()())(cevent->param[0]); switch (cevent->paramNum) { case 1:{ function(); break; } /后面的需要用再添加/ case 2:{ void (function2)(void ) = (void ()(void ))(cevent->param[0]); function2((void )cevent->param[1]); break; } case 3:{ void (function3)(void , void ) = (void ()(void , void ))(cevent->param[0]); function3((void )cevent->param[1], (void )cevent->param[2]); break; } case 4:{ void (function4)(void , void , void) = (void ()(void , void , void))(cevent->param[0]); function4((void )cevent->param[1], (void )cevent->param[2], (void )cevent->param[3]); break; } case 5:{ void (function5)(void , void , void, void) = (void ()(void , void , void, void))(cevent->param[0]); function5((void )cevent->param[1], (void )cevent->param[2], (void )cevent->param[3], (void )cevent->param[4]); break; } case 6:{ void (function6)(void , void , void, void, void) = (void ()(void , void , void, void, void))(cevent->param[0]); function6((void )cevent->param[1], (void )cevent->param[2], (void )cevent->param[3], (void )cevent->param[4], (void )cevent->param[5]); break; } case 7:{ void (function7)(void , void , void, void, void, void) = (void ()(void , void , void, void, void, void))(cevent->param[0]); function7((void )cevent->param[1], (void )cevent->param[2], (void )cevent->param[3], (void )cevent->param[4], (void )cevent->param[5], (void )cevent->param[6]); break; } case 8:{ void (function8)(void , void , void, void, void, void, void) = (void ()(void , void , void, void, void, void, void))(cevent->param[0]); function8((void )cevent->param[1], (void )cevent->param[2], (void )cevent->param[3], (void )cevent->param[4], (void )cevent->param[5], (void )cevent->param[6], (void *)cevent->param[7]); break; } default:{ break; } } }