这是我在网上找的一个比较详细的关于#ifdef __cplusplus extern"C"的解析,
现在我遇到的问题是:
.h 文件
#ifndef LIBPTIHDLC_H
#define LIBPTIHDLC_H
#ifdef __cplusplus
extern "C"
{
#endif //__cplusphus
int PtiHdlcOpen(const int ctrl, const int link, const int baud);#ifdef __cplusplus
}
#endif //__cplusplus
#endif //LIBPTIHDLC_H
.cpp文件
#include <string.h>
#include <stdio.h>
#include <netinet/in.h>
#include "libPtiHdlc.h"
extern "C"
{
#include "mpsproto.h"
int PtiHdlcOpen(const int ctrl, const int link, const int baud)
{
/*
......................................
*/
//int sd= MPSopen(&oreq);(希望调用这个) int sd= MPSopen(); return(sd);
}
mpsproto.h
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
#define MPS_ERROR -1
#ifdef WINNT
#include "mpsio.h"
#include "winntdrv.h"
#endif /* WINNT */
/***
Function prototypes for the API functions. This should be included
by the client applications, and the API files.
***/
#ifdef VXWORKS
#include <semLib.h>
#define sleep(a) taskDelay(sysClkRateGet()*(a))
typedef struct
{
int xTID;
SEM_ID tskSem;
} pti_TaskGlobals;
IMPORT pti_TaskGlobals *Ptg;
IMPORT int MPSerrno;
extern void cleanup_mps_thread ( void );
extern void init_mps_thread ( pti_TaskGlobals* );
#else
/* #8 */
#if defined ( WINNT ) && defined ( _MT )
extern void cleanup_mps_thread ( void );
extern int init_mps_thread ( void );
extern int *_MPSerrno ( void );
#define MPSerrno ( * ( _MPSerrno ( ) ) )
#else
/* #1 */
#if defined(MPS_THREADS) && ((_POSIX_C_SOURCE - 0 >= 199506L) || defined(_REENTRANT))
extern int init_mps_thread ( );
extern int *_MPSerrno ( );
#define MPSerrno ( * ( _MPSerrno ( ) ) )
#else
extern int MPSerrno;
#endif /* (_POSIX_C_SOURCE - 0 >= 199506L) */
#endif /* WINNT && _MT */
#endif /* VXWORKS */
#if defined VMS || defined QNX
/* Map VMS/QNX system error values to what PTI client
applications will expect to receive. */
#define EBADMSG 77
#endif /* VMS || QNX */
#ifdef ANSI_C
#ifdef DECUX_32 /* #3 */
#pragma pointer_size save
#pragma pointer_size long
#endif /* DECUX_32 */
int MPSgetmsg ( MPSsd, struct xstrbuf*, struct xstrbuf*, int* );
int MPSpoll ( struct xpollfd*, int, int );
int MPSputmsg ( MPSsd, struct xstrbuf*, struct xstrbuf*, int );
#ifdef DECUX_32
#pragma pointer_size restore
#endif /* DECUX_32 */
int MPSSysDescriptor ( MPSsd );
int MPSclose ( MPSsd );
int MPSdisabled ( int );
void MPSexit ( int );
int MPSioctl ( MPSsd, int, caddr_t ); /* #9 */
MPSsd MPSopen ( OpenRequest* );(别的文件里面有typedef int MPSsd)
MPSsd MPSMopen ( OpenRequest*,struct sockaddr_in *, int); /* #11 */
#ifndef VMS
MPSsd MPSopenP ( OpenRequest*, int );
int MPSopenS ( OpenRequest* );
#endif /* VMS */
int MPSperror ( char* );
int MPSread ( MPSsd, caddr_t, int );
int MPSwrite ( MPSsd, caddr_t, int );
char *MPSversion ( );
#else
int MPSSysDescriptor ( );
int MPSclose ( );
int MPSdisabled ( );
void MPSexit ( );
int MPSgetmsg ( );
int MPSioctl ( );
MPSsd MPSopen ( );
#ifndef VMS
MPSsd MPSopenP ( );
int MPSopenS ( );
#endif /* VMS */
int MPSperror ( );
int MPSpoll ( );
int MPSputmsg ( );
int MPSread ( );
int MPSwrite ( );
char *MPSversion ( );
#endif /* ANSI_C */#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
我已经声明为extern"C" 为什么在函数实现里面,它不调用MPSopen(&oreq)而调用MPSopen(); 我用MPSopen(&oreq)提示参数太多,后者就没事 问题关键用红色标记了 谢谢了
[ 此帖被20044454在2009-07-17 16:53重新编辑 ]