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;
}
相关文档:
C/C++是最主要的编程语言。这里列出了50名优秀网站和网页清单,这些网站提供c/c++源代码 。这份清单提供了源代码的链接以及它们的小说明。我已尽力包括最佳的C/C++源代码的网站。这不是一个完整的清单,您有建议可以联系我,我将欢迎您的建 议,以进一步加强这方面的清单。
1、http://snippets.dzone.com/tag/c/&nbs ......
这个方块游戏是用linux终端的光标控制、颜色设置做的
(添了个功能,字母P暂停、恢复游戏)
用 A S D W 控制移动、转向,空格键下坠到底;
linux的异步aio函数解决了很多麻烦;
用了个简单的模板单例模式,继承它就可以;
对POSIX线程简单封装成java线程接口;
#include <memory>
#include "Tetris.h"
#include ......
C/C++ development with the Eclipse Platform
Pawel Leszek
摘要:通过本文你将获得如何在Eclipse平台上开发C/C++项目的总体认识。虽然Eclipse主要被用来开发Java项目,但它的框架使得它很容易实现对其他开发语言的支持。在这篇文章里,你将学会如何使用CDT(C/C++ Development Toolkit),一个在Eclipse平台上最 ......
作者:Kevin Lynx 来源:C++博客
转自:http://www.kuqin.com/language/20080319/4797.html
众多C++书籍都忠告我们C语言宏是万恶之首,但事情总不如我们想象的那么坏,就如同goto一样。宏有
一个很大的作用,就是自动为我们产生代码。如果说模板可以为我们产生各种型别的代码(型别替换),
那么宏其实可以为我们在符号上 ......