I was fixing some functions in a piece of someone else code that included a number of functions that took no arguments. They were declared as
return_type_t func();
instead of return_type_t func(void);
Then I found that a bunch of these were put in a array of structs with function pointers. When I fixed the function pointer to take void it gave me another warning since 1 of the function took a char* instead of void ptr.
What's the best solution for this sort of thing without a large rewrite(as the code is complex I was mainly cleaning it up around the edges and wish to avoid changing how it flows)?
struct
定义需要在成员中列出正确的函数类型,如果想要类型安全,则无法解决。
In C, the old-style declaration return_type_t func()
doesn't mean that func
takes no arguments, it means that the number and types of its arguments (if any) are not specified. You cannot just assume that you can add void
inside the parentheses.
Without seeing more of your code, my advice is to investigate each function separately and find out the correct number and types of parameters for each, and then fill out the prototype accordingly.
您可以重写所有原型以采用char *,然后将其转换为(void) parameter
,而该参数(void) parameter
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.