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

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 int value );
发送事件: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++下不支持变参的宏定义,故为了移植平台的方便,不要使用变参的宏定义

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值