C/C++也可以写的很安全!
今天看到一种比较安全的枚举写法!
enum example
{
item1 = 0,
item2,
item3,
item4,
item5,
max /* when you want to add element,please add before this */
};
当你使用它的时候:
example ex1;
if ( 0 <= ex1 && max < ex1 )
{
do something;
}
这样就可以防止枚举异常越界了!max就是上界!
相关文档:
在合作开发时,C#时常需要调用C++DLL,当传递参数时时常遇到问题,尤其是传递和返回字符串是,现总结一下,分享给大家:
VC++中主要字符串类型为:LPSTR,LPCSTR, LPCTSTR, string, CString, LPCWSTR, LPWSTR等
但转为C#类型却不完全相同。
主要有如下几种转换:
将string转为IntPtr:IntPtr System.Runtime.InteropServ ......
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define err(msg) perror(msg)
static void mkdirs(const char *dir)
{
char tmp[1024];
char *p;
&nbs ......
/* Offtimer.c.For auto halt. */
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#define DELAY 60/* Time of sleeping */
int main()
{
time_t now;
struct tm *p;
while(1)
{
now = time(NULL);
&n ......
最强的GUI库当属Qt,毕竟是商业化的东西,功能最完整,什么都好,包括类似java代码风格,良好的框架设计,但有几点值的一提:
1.它没有使用STL,而是自己实现了一套替代方案QTL;
2.事件模型使用自创的signal/slot机制,所以需要moc.exe来预处理头文件;
&nbs ......