一个C++调用C的例子
//cExample.h
#ifndef C_EXAMPLE_H
#define C_EXAMPLE_H
#ifdef __cplusplus
extern "C"
{
#endif
int add(int x, int y);
#ifdef __cplusplus
}
#endif
#endif
---------------------------------
//cExample.c
#include"cExample.h"
int add(int x, int y)
{
return x + y;
}
---------------------------------
//cppFile.cpp
#include <iostream>
#include"cExample.h"
using namespace std;
main()
{
cout<<add(2,3)<<endl;
return 0;
}
--------------------------------
//makefile
cppFile: cppFile.o cExample.o
g++ -g -o cppFile cppFile.o cExample.o
cppFile.o: cppFile.cpp
g++ -g -c cppFile.cpp
cExample.o: cExample.c cExample.h
gcc -g -c cExample.c
clean:
rm -f *.o cppFile
相关文档:
该makefile 只是在linux 中测试过, 若采用hu-ux 只要以下makefile中的gcc 改为aCC 但
hu-ux 未测试
1、首先确定pro*c 工程目录结构
proc/bin
proc/include
proc/lib
proc/src
src/libsrc
src/project_src
&n ......
测试代码一(VC6.0、C-code):
#include <stdio.h>
void main()
{
int aa;
unsigned char j1,j2;
aa=j1=j2=0;
aa=49;
j1=aa;
printf("j1=%d \n",j1);
j2=aa;
printf("j2=%c \n",j2);
}
【分析】:
[1]正如所想象的输出结果:
j1 ......
存储类就是用于存储程序数据的内存的类型,由三个属性来表示:存储时间、作用域和链接。
存储时期描述的是变量占用内存的时间,有静态的、自动的和分配的三种
作用域是变量起到作用的范围,有代码块作用域和文件作用域两种
链接说明该变量可以被哪些地方引用,有空链接、内部链接和外部链接三种
下面是五种存储类的属性 ......
1.求下面函数的返回值(微软)
int func(x)
{
int countx = 0;
while(x)
{
countx
++;
x = x&(x-1);
}
return countx;
}
假定x = 9999。 答案:8
思路:将x转化为2进制,看含有的1的个数。
2. 什么是“引用”?申明和使用“引用”要注意哪些问题?
答:引用就是某个目标变量的&l ......