易截截图软件、单文件、免安装、纯绿色、仅160KB

C++ 调C C调c++

一、c++ 调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
/* c语言实现文件:cExample.c */
#include "cExample.h"
int add( int x, int y )
{
 return x + y;
}
// main.cpp
#include <iostream>
using namespace std;
// c++实现文件,调用add()
#include "cExample.h"
 
int main(int argc, char* argv[])
{
 cout << add(2,3) << endl;
 return 0;
}
二、C调C++
//C++头文件 cppExample.h
#ifndef CPP_EXAMPLE_H
#define CPP_EXAMPLE_H
#ifdef __cplusplus
extern "C"
{
#endif
 int add(int x,int y);
#ifdef __cplusplus
}
#endif
#endif
//C++实现文件 cppExample.cpp
#include "cppExample.h"
int add( int x, int y )
{
return x + y;
}
/* C实现文件 */
#include <stdio.h>
#include "cppExample.h"
int main( int argc, char* argv[] )
{
  printf ("%d\n", add( 2, 3 ));
 return 0;
 
}


相关文档:

GNU/Linux平台的C程序开发及程序运行环境

本文介绍在GNU/Linux环境下一个C程序由源代码到程序,到加载运行,最后终止的过程。同时以此过程为载体,介绍GNU/Linux平台下软件开发工具的使用。
 
本文以我们最常见的hello, world!为例:
 
#include <stdio.h>
main ()
{
      printf(“hello, world!\n” ......

Linux I2C Input设备驱动代码的几点理解

最近在做一个I2C键盘的Linux驱动,参考了其他芯片的一些代码,其中陆续发现有些让人迷惑的东西,把我的迷惑及理解在这里加以记录:
1. i2c_driver结构体的probe成员的原型:
     int (*probe)(struct i2c_client *, const struct i2c_device_id *);
即:probe函数被调用时会从上边传两个个参 ......

C库函数(字符串函数)


C库函数
字符串函数
 
 
 
函数名
函数原型
功能
返回值
包含头文件
strcat
char *strcat(char *st1, char *str2)
把str2连接到str1后面
str1
string.h
strchr
char *strchr(char *str, int ch)
找出str指向的字符串中第一次出现字符串ch的位置
指向该位置的指针,未找到则返回空指针
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号