单引号在c语言中作用,在多个字符中使用单引号在C ++中有什么作用?

They're really just ints. They're used extensively in the Core Audio API enum's for example, in the CoreAudioTypes.h header file,

enum

{

kAudioFormatLinearPCM = 'lpcm',

kAudioFormatAC3 = 'ac-3',

kAudioFormat60958AC3 = 'cac3',

kAudioFormatAppleIMA4 = 'ima4',

kAudioFormatMPEG4AAC = 'aac ',

kAudioFormatMPEG4CELP = 'celp',

} ;

There's a lot of chatter about this not being "platform independent", but when you're using an api that's made for a specific platform, who cares about portability. Checking for equality on the same platform will never fail. These enum'd values are easier to read and they actually contain their identity in their value, which is pretty nice.

What I've tried to do below is wrap a multibyte character literal up so it can be printed (on Mac this works). The strange thing is, if you don't use up all 4 characters, the result becomes wrong below..

#include

#define MASK(x,BYTEX) ((x&(0xff<<8*BYTEX))>>(8*BYTEX))

struct Multibyte

{

union{

int val ;

char vals[4];

};

Multibyte() : val(0) { }

Multibyte( int in )

{

vals[0] = MASK(in,3);

vals[1] = MASK(in,2);

vals[2] = MASK(in,1);

vals[3] = MASK(in,0);

}

char operator[]( int i ) {

return val >> (3-i)*8 ; // works on mac

//return val>>i*8 ; // might work on other systems

}

void println()

{

for( int i = 0 ; i < 4 ; i++ )

putc( vals[i], stdout ) ;

puts( "" ) ;

}

} ;

int main(int argc, const char * argv[])

{

Multibyte( 'abcd' ).println() ;

Multibyte( 'x097' ).println() ;

Multibyte( '\"\\\'\'' ).println() ;

Multibyte( '/*|' ).println() ;

Multibyte( 'd' ).println() ;

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值