现在的位置: 首页 > 综合 > 正文

跨平台软件开发相关事宜 (window vc++6.0 & linux)

2013年04月25日 ⁄ 综合 ⁄ 共 2213字 ⁄ 字号 评论关闭
文章目录

1 变量声明的位置

vc++6.0 不支持在代码中间声明变量。所以最好变量统一在函数的开始处统一进行声明。

2 inline 关键字

在vc++6.0下是__inline, 所以要修改工程属性,在project->[setting]->[c/c++]->Preprocessor
definitions:编辑框里输入inline=__inline即可。

3fatal
error C1010: unexpected end of file while looking for precompiled header directive
 

选中文件,右键设置-》c/c++-》分类中选择预统的头文件-》选中不使用预补偿页眉

4 休眠函数

linux下为sleep(n),休眠n秒;另外还提供一个微秒级函数usleep(n);

vc++为Sleep(n) ,休眠n毫秒,注意第一个字母为大写

5  系统节拍

vc++ :GetTickCount(),单位为毫秒
linux:int gettimeofday(struct  timeval*tv,struct  timezone *tz )
struct  timeval{
       
long  tv_sec;/*秒*/
        long  tv_usec;/*微妙*/
};
struct  timezone{
        int tz_minuteswest;/*和greenwich 时间差了多少分钟*/
        int tz_dsttime;/*type of DST correction*/
};

6 错误代码

vc++:GetLastError()
linux:errno

7 临界区

vc++:CRITICAL_SECTION

初始化:void WINAPI InitializeCriticalSection(_Out_  LPCRITICAL_SECTION lpCriticalSection);

进入临界区:void WINAPI EnterCriticalSection(_Inout_
 LPCRITICAL_SECTION lpCriticalSection
);

退出临界区:void WINAPI LeaveCriticalSection(_Inout_  LPCRITICAL_SECTION lpCriticalSection);

销毁临界区:void WINAPI DeleteCriticalSection(_Inout_  LPCRITICAL_SECTION lpCriticalSection);

linux:pthread_mutex_t

初始化:int pthread_mutex_init(pthread_mutex_t
*restrict 
mutex,const pthread_mutexattr_t *restrict attr);

进入临界区:int pthread_mutex_lock(pthread_mutex_t *mutex);

退出临界区:int pthread_mutex_unlock(pthread_mutex_t *mutex);

销毁临界区:int pthread_mutex_destroy(pthread_mutex_t *mutex);

8 线程创建

vc++:线程id:uintptr_t 
创建线程:uintptr_t _beginthread( void( *start_address )( void * ),unsigned stack_size,void *arglist );
销毁线程:void _endthread( void );
linux:线程id:pthread_t
创建线程:int pthread_create(pthread_t *thread,
const pthread_attr_t *
attr,void *(*start_routine)(void*),
void *
arg);
销毁线程:void pthread_exit(void *value_ptr);

9 事件

vc++:事件句柄HANDLE
事件初使化:HANDLE WINAPI CreateEvent(_In_opt_  LPSECURITY_ATTRIBUTES lpEventAttributes,_In_      BOOL bManualReset, _In_
     BOOL bInitialState, _In_opt_  LPCTSTR lpName);
发送事件:BOOL WINAPI SetEvent(_In_  HANDLE hEvent);
等待一个事件:DWORD WINAPI WaitForSingleObject( _In_  HANDLE hHandle, _In_  DWORD dwMilliseconds);
事件销毁:BOOL WINAPI CloseHandle(_In_  HANDLE hObject);
linux:事件句柄sem_t (注,信息号并不是唯一替换方式)
事件初使化:int sem_init(sem_t *sem,
int
pshared, unsigned intvalue);
发送事件:int sem_post(sem_t *sem);
等待一个事件的到达:int sem_timedwait(sem_t *restrict sem,const struct timespec *restrict abs_timeout);
事件销毁:int sem_destroy(sem_t *sem);

10 变参的宏定义

vc++下不支持变参的宏定义,故为了移植平台的方便,不要使用变参的宏定义

抱歉!评论已关闭.