如何写出专业的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
相关文档:
设置:
1. Tools/Projects and Solutions/VC ++ Directories
Inlcude files: C:\Program Files\MATLAB\R2009a\extern\include
Library files: C:\Program Files\MATLAB\R2009a\extern\lib
2. Property
Configuration Properties/Linker
......
1.求下面函数的返回值( 微软)
int func(x)
{
int countx = 0;
while(x)
{
countx ++;
x = x&(x-1);
  ......
用过vista的朋友都知道 vista不知由于什么原因很多编译软件都不能正常工作了 vs6.0全部都说有已知的兼容性问题存在
当然你可以装好几个g的vs2005
寡人一直都想自学一门计算机语言
但是苦于找不到编译器
连最简单的hellowold都不能正常编译
汗
不多说
看我弄得
总算能用了
1.下载MinGW
http://sourceforge.net/pro ......
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 ......