两种不可移植的特性: 位域和 volatile
1. 位域 ( bit-field )
类可以将其( 非静态) 数据成员定义成位域 , 在一个位域中含有一定数量的二进制位。
- 位域的类型必须是整型或枚举类型
- 位域在内存中的布局是与机器相关的
typedef unsigned int Bit;
class File {
Bit mode: 2;
Bit modified: 1;
Bit prot_owner: 3;
Bit prot_group: 3;
Bit prot_world: 3;
public:
enum modes {READ = 01, WRITE = 02, EXECUTE = 03};
File &open(modes);
void close();
void write();
bool isRead() const;
void setWrite();
}
// 使用位域
void File::write() {
modified = 1;
// ...
}
void File::close() {
if( modified)
// ...保存内容
}
File &File::open(File::modes m) {
mode |= READ; // 按默认方式设置READ
// 其他处理
if(m & WRITE) // 如果打开了READ和WRITE
// 按照读/写方式打开文件
return *this;
}



