*(__cdecl *)(void)错误
在移植x264编码的过程中,在vc60的环境下的mfc应用程序中,在win32console下就可以通过,遇到在x264代码中x264.c文件中的函数:
static int Parse( int argc, char **argv, x264_param_t *param, cli_opt_t *opt )
的编译错误,
是此函数调用了如下函数:
c = getopt_long( argc, argv, "hi:I:b:r:cxB:q:f:o:A:m:p:t:vw8",
long_options, &long_options_index);
来解析main函数的输入参数,出现如下错误:
error C2664: 'getopt_long' : cannot convert parameter 1 from 'int' to 'int *(__cdecl *)(void)'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
把此函数改成如下样子:
c = getopt_long( (int *(__cdecl *)(void))argc, argv, "hi:I:b:r:cxB:q:f:o:A:m:p:t:vw8",
long_options, &long_options_index);
又出下如下错误:
error C2664: 'getopt_long' : cannot convert parameter 2 from 'char ** ' to 'char *const **(__cdecl *)(void) '
There is no context in which this conversion is possible
改成如下样子,就可以编译通过:
c = getopt_long( (int *(__cdecl *)(void))argc, (char *const **(__cdecl *)(void))argv, "hi:I:b:r:cxB:q:f:o:A:m:p:t:vw8",
long_options, &long_options_index);
此函数在文件getopt.h中定义,在getopt.c中申明,在getopt.h中如下所示:
extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
const struct option *__longopts, int *__longind);
也可以把getopt.h改成如下样子,也可以通过编译:
extern int getopt_long (int argc, char *const *argv, const char *__shortopts,
const struct option *__longopts, int *__longind);
不知道为什么两个下划线影响编译,估计是__cdecl的问题,在vc6下setting里,c/c++下的category中选择code generation,
在calling convertion中全部选择一遍也不能通过编译