g++编译C语言函数 混合编程 有点意思??
函数声明:
#ifndef PUB_FUNC_H
#define PUB_FUNC_H
#ifdef __cplusplus
extern "C"
{
#endif
unsigned char *LTrim(unsigned char *str);
#ifdef __cplusplus
}
#endif
#endif
函数实现
unsigned cha *LTrim(unsigned cha *str)
{
unsigned int len = 0;
unsigned int low = 0;
if(NULL == str)
{
printf("The Parameter Is Invalid.pStrTime = NULL.\n");
goto EXIT_LABEL;
}
len = strlen(str);
while((low<len)&&isspace(str[low]))
{
low++;
}
strcpy(str,str+low);
EXIT_LABEL:
return str;
}
然后 g++ ./source/pub_func.c 出现错误!!
source/pub_func.c:41: error: invalid conversion from 'unsigned char*' to 'const char*'
source/pub_func.c:41: error: initializing argument 1 of 'size_t strlen(const char*)'
source/pub_func.c:42: error: 'isspace' was not declared in this scope
source/pub_func.c:46: error: invalid conversion from 'unsigned char*' to 'char*'
source/pub_func.c:46: error: initializing argument 1 of 'char* strcpy(char*, const char*)'
source/pub_func.c:46: error: invalid conversion from 'unsigned char*' to 'const char*'
source/pub_func.c:46: error: initializing argument 2 of 'char* strcpy(char*, const char*)'
strlen 原型 strlen(const char *s);
strcpy 原型 strcpy(char *dest, const char *src);
我也知道 是类型不匹配,但是我的疑问是:
我在声明生的时候 写了 extern "C" 为什么用g++编译的时候还提示 无法类型转换呢??