如何写出专业的C头文件
做到专业,应该是每个职业程序员应该要求自己做到的。
让我们看看lua
是
怎么写头文件的。
1.License Agreement
License
Agreement
应该加在每个头文件的顶部。
Lua Sample:
/*
** $Id: lua.h,v 1.175b 2003/03/18 12:31:39 roberto Exp $
** Lua - An Extensible Extension Language
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
**
http://www.lua.org
mailto:info@lua.org
** See Copyright Notice at the end of this file
*/
2.guard define
整个头文件应该在guard
define
之间
#ifndef lua_h
#define
lua_h
#endif
另外,如果这个头文件可能给
c++
使用,要加上
#ifdef __cplusplus
extern
"
C
"
{
#endif
/*
The lines within extern "C"
*/
#ifdef __cplusplus
}
#endif
3.
尽量不要在头文件中暴露数据结构
这样可以用户对你的实现的依赖,也减少了用户的编译时间
typedef
struct
lua_State lua_State;
LUA_API lua_State
*
lua_open (
void
);
LUA_API
void
lua_close (lua_State
*
L);
可以看到虽然用户会一直使用
lua_State,
但是并不知道
lua_State
的
结构是什么
从一个使用
lua
的例子程序可以看出:
#include
"
lua.h
"
#include
"
lauxlib.h
"
#include
"
lualib.h
"
int
main(
int
argc,
char
*
argv[])
{
lua_State
*
L
=
lua_open();
const
char
*
buf
=
"
var = 100
"
;
int
var ;
luaopen_base(L);
luaopen_io(L);
lua_dostring(L, buf);
&n
相关文档:
与 &: 任何位用&运算与0结合结果为0,与1结合结果为其本身;
或 | : 任何位用|运算与0结合结果为其本身,与1结合结果为1;
异或 ^ : 任何位用^运算与0结合结果为其本身,与1结合则取反; ......
int svd(int m,int n,int withu,int withv,double eps,double tol,
double *a, double *q, double *u, double *v, double *vt)
{
int i,j,k,l,l1,iter,retval;
double c,f,g,h,s,x,y,z;
double *e;
e = (double *)calloc(n,sizeof(double));
retval = 0;
/* Cop ......
In C++, how do i go about using setenv to set the display? I need to set it like this:
export DISPLAY=0.0
1、setenv("DISPLAY",":0.1",1);
If you're calling the xrandr functions from your C++ program, then I would expect setenv() should work for you. The 3rd argument of 1 tells setenv() to ov ......
问题描述:
C#程序,里面copy了许多原来的代码,所以参差不齐的,很难读,如何才能让代码自动排齐,就象VS 6.0中可以使用快捷键,非常方便.
解答:
ctrl+a,先全选
ctrl+k,ctrl+f,自动排列
或者
ctrl+a,先全选
alt+F8 自动排列 ......
转
载自http://www.builder.com.cn/
static
是c++中很常用的修饰符,它被用来控制变量的存储方式和可见性,下面我将从 static 修饰符的产生原因、作用谈起,全面分析static
修饰符的实质。
static 的两大作用:
一、控制存储方式:
static被引入以告知编译器,将变 ......