Symbian 数据类型详解
2010-03-10 16:21:00 来源:WEB开发网console->Printf(OutChar,ch16);
console->Printf(OutChar,ch162);
3.布尔型
(1)typedef int TBool;
(2)布尔型可以认为是特殊的整型,布尔型有两个取值,分别是ETrue、EFalse;
(3)由于C++编译器认为所有非零值均为真,所以一般避免布尔型的变量和ETrue进行比较,而使用以下方法
if(iBool)
{ ...
}
if(!iBool)
{ ...
}
如:
//测试布尔型
_LIT(Result,"%s");
TBool iBool1 = ETrue;
TBool iBool2 = EFalse;
if(iBool1)
{ console->Write(_L("ibool1 is True ")); }
if(!iBool2)
{ console->Write(_L("_ibool2 is False ")); }
4.浮点型
(1)typedef float TReal32;
(2)typedef double TReal64;
(3)typedef double TReal;
(4)通常情况下避免使用浮点数,以精度换速度。
如:
//测试浮点型
_LIT(OutReal,"%f ");
TReal32 real32 = 18.6;
TReal64 real64 = 78.5;
TReal real642 = 99.56;
console->Printf(OutReal,real32);
console->Printf(OutReal,real64);
console->Printf(OutReal,real642);
//以精度换取速度
TInt OldFunction(TInt aTop,TInt aBottom)
{
TReal a = (TReal)aTop;
TReal b = (TReal)aBottom;
TReal c = a/b + 0.5;
TReal result;
Math::Round(result,c,0);
return result;
}
TInt newFunction(TInt aTop,TInt aBottom)
{ return(2*aTop + aBottom)/(2*aBottom); }
console->Printf(OutInt,OldFunction(20,30));
console->Printf(OutInt,newFunction(20,30));
5.空类型
(1)typedef void TAny;
(2)TAny通常只用于指针,可用于参数,返回类型
如:
static TUint8 *Copy(TAny *aTrg,const TAny *aSrc,TInt aLength);
TAny setX(TInt aX);
6.枚举型
enum TState{EOff,EInit,EOn};
TState state1 = EOff;
if(state1 == EOff)
{ console->Write(_L("Current State is OFF")); }
更多精彩
赞助商链接