其他的.c文件使用void update_compare(EPWM_INFO*)函数该怎么调用
请问高手:typedef struct
{
volatile struct EPWM_REGS *EPwmRegHandle;
Uint16 EPwm_CMPA_Direction;
Uint16 EPwm_CMPB_Direction;
Uint16 EPwmTimerIntCount;
Uint16 EPwmMaxCMPA;
Uint16 EPwmMinCMPA;
Uint16 EPwmMaxCMPB;
Uint16 EPwmMinCMPB;
}EPWM_INFO;
// Global variables used in this example
EPWM_INFO epwm4_info;
void update_compare(EPWM_INFO*);
想在其他的.c文件使用void update_compare(EPWM_INFO*)函数该怎么调用,直接调用的话显示undefined。
请赐教: 文件内普通函数会自动成为外部可调用的函数,但用inline和static声明的函数都不能从外部调用。
当函数是定义在.h文件(头文件)时,用extern是不行得,应该要include,但是如果是定义在.cpp时,调用
时就应用extern 声明(其实,也可以不用extern关键词,但是一定要声明这个函数,注意:是声明,不是定
义)
关于调用:
也即是初次声明时,绝不可用extern;
初次声明并定义时,用不用extern无所谓,函数都可被调用;
调用函数时,必须先声明这个函数,但用不用extern无所谓;
下面是我的一个例子:
**********************************************************
//a.h //这里的函数用于被包含
#ifndef AAA
#define AAA
#include<iostream.h>
void fun(){
cout<<"fun()"<<endl;
}
#endif
************************************************************
// aa.cpp //这里的函数用于被调用
#include<iostream.h>
void fun2(){ //此处可为extern void fun2(){},
//但必须有{},
//不能为“extern void fun2();!!!
//然后再void fun2(){};!!!”
cout<<"fun2()"<<endl;
}
*************************************************************
// main.cpp //驱动程序
#include<iostream.h>
#include"a.h"
void fun2(); //此处也可为:extern void fun();
void main(){
fun();
fun2();
}
页:
[1]