Google的C++编程规范里的几点
2011-03-08 14:57:05| 分类:
R&D
| 标签:
|举报
|字号大中小 订阅
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml
Don't use an #include when a forward declaration would suffice.
Use streams only for logging.
Use 0 for integers, 0.0 for reals, NULL for pointers, and '\0' for chars.
Use sizeof(varname) instead of sizeof(type) whenever possible.
Use only spaces, and indent 2 spaces at a time.
Remember that sizeof(void *) != sizeof(int).
You may need to be careful with structure alignments, particularly for structures being stored on disk. Any class/structure with a int64_t/uint64_t member will by default end up being 8-byte aligned on a 64-bit system. If you have such structures being shared on disk between 32-bit and 64-bit code, you will need to ensure that they are packed the same on both architectures. Most compilers offer a way to alter structure alignment. For gcc, you can use __attribute__((packed)). MSVC offers #pragma pack() and __declspec(align()).
Use the LL or ULL suffixes as needed to create 64-bit constants. For example:
int64_t my_value = 0x123456789LL;
uint64_t my_mask = 3ULL << 48;
Do not use C++ exceptions.
评论这张
转发至微博
转发至微博
评论