跨平台软件开发相关事宜 (window vc++6.0 & linux)
2013-06-16 17:18
495 查看
1 变量声明的位置
vc++6.0 不支持在代码中间声明变量。所以最好变量统一在函数的开始处统一进行声明。2 inline 关键字
在vc++6.0下是__inline, 所以要修改工程属性,在project->[setting]->[c/c++]->Preprocessordefinitions:编辑框里输入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++下不支持变参的宏定义,故为了移植平台的方便,不要使用变参的宏定义相关文章推荐
- Linux平台下基于BitTorrent应用层协议的下载软件开发--peer交互模块(torrent.c)
- Linux平台下基于BitTorrent应用层协议的下载软件开发--出错处理模块(bterror.c)
- Linux平台下基于BitTorrent应用层协议的下载软件开发--peer模块(peer.h)
- Linux平台下基于BitTorrent应用层协议的下载软件开发--peer交互模块(torrent.h)
- Linux平台下基于BitTorrent应用层协议的下载软件开发--出错处理模块(bterror.h)
- Linux平台下基于BitTorrent应用层协议的下载软件开发--策略管理模块(policy.c)
- Linux平台下基于BitTorrent应用层协议的下载软件开发--tracker服务器交互模块(tracker.c)
- Linux平台下基于BitTorrent应用层协议的下载软件开发--缓冲管理模块(data.c)
- Linux平台下基于BitTorrent应用层协议的下载软件开发--策略管理模块(policy.h)
- 谈谈国内开发的Linux手机软件平台Broncho,兼谈Android、Openmoko等[转]
- Linux平台上的多种软件安装方式与更友好的包管理相关软件介绍
- GIS软件开发包Map Suite v10.0发布,支持Windows、Linux和macOS多平台
- GIS软件开发包Map Suite v10.0发布,支持Windows、Linux和macOS多平台
- Linux平台下基于BitTorrent应用层协议的下载软件开发--缓冲管理模块(data.h)
- Linux平台下基于BitTorrent应用层协议的下载软件开发--哈希模块(sha1.c)
- Linux平台下基于BitTorrent应用层协议的下载软件开发--tracker服务器交互模块(tracker.h)
- 谈谈国内开发的Linux手机软件平台Broncho,兼谈Android、Openmoko等[转]
- Linux平台下程序开发必不可少的工具软件
- 一起高效写代码,软件开发平台「CircleCI」获C轮3100万美元融资命令_Linux 一起高效写代码,软件开发平台「CircleCI」获C轮3100万美元融资 命令用法详解:
- Linux平台下基于BitTorrent应用层协议的下载软件开发--日志管理模块(log.c)