读书人

关于inline的有关问题

发布时间: 2012-02-24 16:30:39 作者: rapoo

关于inline的问题
在网上打到一LINUX的代码

其中有一段是这样的

inline bool bit_on(unsigned char ui,int pos){return ui&(1 < <pos);}
inline void bit_setone(unsigned char& ui,int pos){ui|=1 < <pos;}
inline void bit_setzero(unsigned char& ui,int pos){ui&=~(1 < <pos);}

在linux下用g++编译通过,而且可以执行

但在C++ Builder 6 总报错,去掉inline也不能编译

怎么解决???

[解决办法]
bool 换为int即可
[解决办法]
在BCB 2006下运行正常。

//---------------------------------------

#include <vcl.h>
#pragma hdrstop
#include <stdio.h>

//---------------------------------------

#pragma argsused

inline bool bit_on(unsigned char ui,int pos){return ui&(1 < <pos);}
inline void bit_setone(unsigned char& ui,int pos){ui|=1 < <pos;}
inline void bit_setzero(unsigned char& ui,int pos){ui&=~(1 < <pos);}

int main(int argc, char* argv[])
{
bool t;

t = bit_on( 'd ', 5);
printf( "%d\r\n ", t);
scanf( "%*c ");

return 0;
}
//---------------------------------------

读书人网 >C++ Builder

热点推荐