Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
o) 允许默认参数?:FUNC_API(int)函数(…,void*ptr=0) @ AbBiWords:外部C是允许C++代码调用C代码的。如果您将它包装在#ifdef u cplusplus中,那么它就不是问题,因为它不包含在C编译中。你真的应该在问题_C++_C_Visual Studio 2010 - Fatal编程技术网

o) 允许默认参数?:FUNC_API(int)函数(…,void*ptr=0) @ AbBiWords:外部C是允许C++代码调用C代码的。如果您将它包装在#ifdef u cplusplus中,那么它就不是问题,因为它不包含在C编译中。你真的应该在问题

o) 允许默认参数?:FUNC_API(int)函数(…,void*ptr=0) @ AbBiWords:外部C是允许C++代码调用C代码的。如果您将它包装在#ifdef u cplusplus中,那么它就不是问题,因为它不包含在C编译中。你真的应该在问题,c++,c,visual-studio-2010,C++,C,Visual Studio 2010,o) 允许默认参数?:FUNC_API(int)函数(…,void*ptr=0) @ AbBiWords:外部C是允许C++代码调用C代码的。如果您将它包装在#ifdef u cplusplus中,那么它就不是问题,因为它不包含在C编译中。你真的应该在问题中提到这一点。更好的是,发布代码。@AmberWilds这似乎不正确,因为你可以看到他们两个都独立地在C99中工作:(可能是VS特性)@AmberWilds:如果你必须同时做这两件事,那么你仍然有问题。类似地,Type1需要是一个typedef


o) 允许默认参数?:
FUNC_API(int)函数(…,void*ptr=0) @ AbBiWords:外部C是允许C++代码调用C代码的。如果您将它包装在
#ifdef u cplusplus
中,那么它就不是问题,因为它不包含在C编译中。你真的应该在问题中提到这一点。更好的是,发布代码。@AmberWilds这似乎不正确,因为你可以看到他们两个都独立地在C99中工作:(可能是VS特性)@AmberWilds:如果你必须同时做这两件事,那么你仍然有问题。类似地,
Type1
需要是一个typedef别名,而不是一个类或直接结构。对不起,实际上我不必同时做这两件事。我把第二个选项看错了。谢谢你的帮助@彼得:有些事情对我来说还是没有意义。。。大概,外部“C”中的任何东西都是C代码,是吗?为什么我必须更改头文件(extern“C”块中的代码)才能将其编译为C代码?@AmberWilds我不太确定,我认为没有关于
extern“C”
的官方规范,它表示C链接。所以,只是一个简单的问题,而不是函数应该如何调用。应该是C,但我不知道是否需要VS@AmberWilds这似乎是不对的,因为你可以看到他们两人都独立地在C99中工作:(也许这是一种VS特质)@AmberWilds:如果你必须同时做这两件事,那么你仍然有一些问题。类似地,
Type1
需要是一个typedef别名,而不是一个类或直接结构。对不起,实际上我不必同时做这两件事。我把第二个选项看错了。谢谢你的帮助@彼得:有些事情对我来说还是没有意义。。。大概,外部“C”中的任何东西都是C代码,是吗?为什么我必须更改头文件(extern“C”块中的代码)才能将其编译为C代码?@AmberWilds我不太确定,我认为没有关于
extern“C”
的官方规范,它表示C链接。所以,只是一个简单的问题,而不是函数应该如何调用。应该是C,但我不知道是否需要是VS
#include "header_file.h"

int main(){
  return 0;
}
#ifdef __cplusplus
extern "C" {
#endif

#include defines_file.h

FUNC_API(int) Function(Type1 var1, Enum2 var2, Type3 var3, void* ptr=0);

#ifdef __cplusplus
}
#endif
enum Enum2{
//enumerator list
};
1>c:\header_file\include\header_file.h(78): error C2146: syntax error : missing ')' before identifier 'var2'
1>c:\header_file\include\header_file.h(78): error C2081: 'Enum2' : name in formal parameter list illegal
1>c:\header_file\include\header_file.h(78): error C2061: syntax error : identifier 'var2'
1>c:\header_file\include\header_file.h(78): error C2059: syntax error : ';'
1>c:\header_file\include\header_file.h(78): error C2059: syntax error : ','
1>c:\header_file\include\header_file.h(78): error C2059: syntax error : ')'
//replace this:
enum Enum2{A,B,C,D};

//with this
typedef enum{A,B,C,D} Enum2;
FUNC_API(int) Function(Type1 var1, enum Enum2 var2, Type3 var3, void* ptr);
struct Type1  //this is passed as "struct Type1 pName"
{
    int a,b,c;
};

typedef struct //this is passed as "Type2 pName"
{
    int a,b,c;
}Type2;

//this is passed as either "struct type3 pName" or "type3_t pName"
typedef struct type3
{
    int a,b,c;
}type3_t;
#if defined __cplusplus
extern "C"
{
#endif
    // Declarations must be valid C syntax
    int function() ;
#if defined __cplusplus
}
#endif
extern "C"
{
    // Declarations must be valid C syntax
    int function() ;  
}
    // Declarations must be valid C syntax
    int function() ;