69,371
社区成员
发帖
与我相关
我的任务
分享
#ifndef __gg_h_
#define __gg_h_
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
long g_lDecInH;
void SetA(long val);
void GetA(long* pval);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif /* __gg_h_ */
#include "h1.h"
#include <iostream>
void SetA(long val){
g_lDecInH = val;
}
long GetA(){ //不要写成GetA(long *p)最好用返回值。
return g_lDecInH;
}
void f1(){
long l = 123;
SetA(l);
printf("%d\n",g_lDecInH);
}
void f2(long* p){
*p = GetA();
printf("%d\n",*p);
}
int main()
{
long p = 0;
f1();
f2(&p);
printf("%d\n",p);
system("pause");
return 0;
}
这样是没问题的。
// gg.h
#ifndef __GG_H_
#define __GG_H_
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
long g_lDecInH;
void SetA(long val);
void GetA(long *pval);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // __GG_H_
// gg.c
#include "gg.h"
void SetA(long val)
{
g_lDecInH = val;
}
void GetA(long *pval)
{
*pval = g_lDecInH;
}
// main.c
#include <stdio.h>
#include "gg.h"
void foo1()
{
long tmp;
printf("Input a number: ");
scanf("%d", &tmp);
SetA(tmp);
}
void foo2()
{
long tmp;
GetA(&tmp);
printf("Your input: %ld\n", tmp);
}
int main(void)
{
foo1();
foo2();
return 0;
}