是无效**在ANSI-C可以接受的类型? [英] Is void** an acceptable type in ANSI-C?
问题描述
我所看到的,其原型是一个函数:
I have seen a function whose prototype is:
int myfunc(void** ppt)
此函数被调用在C文件
A = MYFUNC(MYSTRUCT ** VAR1);
This function is called in a C file as a = myfunc(mystruct **var1);
其中MYSTRUCT是的typedef结构,我们有一个。
where mystruct is typedef for one of structure we have.
这个工程没有在任何MSVC6.0编译错误,但是,当我与其他一些C编译器编译它,它给在一个地方错误的调用该函数与错误消息:
This works without any compilation errors in MSVC6.0, But when I compile it with some other C compiler, it gives an error at the place where this function is called with error message:
类型MYSTRUCT的论证**是不符合void类型的参数**
在myfunc()的参数保持为无效**,因为它似乎是一个通用的malloc一种功能与各种结构变量类型的内存分配
The argument of myfunc() is kept as void** because it seems to be a generic malloc kind of function to be called with various structure variable types for memory allocation
- 有什么类型,如无效**允许C标准/任何C编译器?
- 如何解决这个问题? [我试过铸造函数调用参数
MYSTRUCT **
,但它没有工作]
- Is there any type such as void ** allowed in C standard/any C compilers?
- How do I fix this? [I tried casting the function call argument to
mystruct**
, but it didn't work]
-AD
推荐答案
无效**
的是的有效,但是,根据您的错误信息,你可能有显式转换参数如下:
void**
is valid but, based on your error message, you probably have to explicitly cast the argument as follows:
mystruct **var1;
x = myfunc ((void**) var1);
这是因为 MYFUNC
函数期待无效**
键入。而无效*
可隐式转换为任何其他指针,事实并非如此的双指针 - 你需要显式转换为
That's because the myfunc
function is expecting the void**
type. While void*
can be implicitly cast to any other pointer, that is not so for the double pointer - you need to explicitly cast it.
这篇关于是无效**在ANSI-C可以接受的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!