2011年8月19日

C和C++混合编程(转)

摘要: C++项目中的extern "C" {}引言在用C++的项目源码中,经常会不可避免的会看到下面的代码:view sourceprint?1#ifdef __cplusplus 2extern "C" { 3#endif 45/*...*/67#ifdef __cplusplus 8} 9#endif它到底有什么用呢,你知道吗?而且这样的问题经常会出现在面试or笔试中。下面我就从以下几个方面来介绍它:1、#ifdef _cplusplus/#endif _cplusplus及发散 2、extern "C" 2.1、extern关键字2. 阅读全文

posted @ 2011-08-19 17:32 原来... 阅读(20730) 评论(3) 推荐(2)

C语言中如何在main函数开始前执行函数

摘要: 在gcc中,可以使用attribute关键字,声明constructor和destructor,代码如下:view plain#include<stdio.h>__attribute((constructor))voidbefore_main(){printf("%s/n",__FUNCTION__);}__attribute((destructor))voidafter_main(){printf("%s/n",__FUNCTION__);}intmain(intargc,char**argv){printf("%s/n" 阅读全文

posted @ 2011-08-19 13:13 原来... 阅读(5092) 评论(0) 推荐(0)

typedef常见用法(转)

摘要: typedef常见用法1.常规变量类型定义例如:typedef unsigned char uchar描述:uchar等价于unsigned char类型定义 uchar c声明等于unsigned char c声明2.数组类型定义例如:typedef int array[2];描述:array等价于 int [2]定义; array a声明等价于int a[2]声明扩展:typedef int array[M][N];描述:array等价于 int [M][N]定义; array a声明等价于int a[M][N]声明3.指针类型定义例如: typedef int *pointer;描述:p 阅读全文

posted @ 2011-08-19 12:58 原来... 阅读(9535) 评论(1) 推荐(2)

导航