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

如何写出专业的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 
*

=
 lua_open();
    
const
 
char
 
*
buf 
=
 
"
var = 100
"
;
    
int
 var ;
    luaopen_base(L);
    luaopen_io(L);
    lua_dostring(L, buf);
   &n


相关文档:

简述C和C++程序员学习历程

哈哈!有幸在某网站发现这篇文章,读罢,觉得蛮有道理,发来大家一起共勉之    
总是被同学们问到,如何学习C和C++才不茫然,才不是乱学,想了一下,这里给出一个总的回复。 
' J$ |0 ?! p% w" t5 D6 D: c9 |0 B
  一家之言,欢迎拍砖哈。 
  1、可以考虑先学习C. 
/ U$ X+ X/ P; Y ......

使用C语言扩展Python(五)

上一篇中我们在python端的做法是每次读取一个数据块,然后将这个数据块传递进C扩展模块中去,但对于目标文件的数据写入是在C扩展模块中完成的,但其实可以更面向对象一点,不是吗?原来outfp是一个文件指针,不如改成一个从Python中传递一个文件对象到C模块里去,这个文件对象有自己的write方法,这样在C扩展模块中你就可以 ......

用C/C++程序控制环境变量

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 ......

怎样在visual studio.NET 让C,C++,C#代码自动排齐

问题描述:
C#程序,里面copy了许多原来的代码,所以参差不齐的,很难读,如何才能让代码自动排齐,就象VS   6.0中可以使用快捷键,非常方便.
解答:
ctrl+a,先全选   
ctrl+k,ctrl+f,自动排列
或者
ctrl+a,先全选
alt+F8 自动排列 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号