CPP

C,CPP Programming & Variable Naming Rules

2016-06-08. Category & Tags: C, CPP

File Ambiguity # file: can be only filename, or full/relative path + filename. location: full/relative path + filename. filename: only name part, no path in string. path: full/relative path w/o filename. Common & Suggested Usages # //Common → Suggested chars → charSize bytes → byteSize int * buf → int *p_intListing char * buf → char *p_inputFile ifstream in→ ifstream inputStream IF Statement Evaluation # if (c) is: if(c ! ...

C-CPP-Programming-in-case-of

Category & Tags: C, C++, CPP, Programming

Data Structure Alignment 数据结构对齐 # x86-64 architecture # Overall rule: any data structure/element should be accessed by CPU with minimum CPU cycles. A 32bit CPU can access 4Bytes in one cycle, while a 64bit one can access 8Bytes. When a memory access is not aligned, it is said to be misaligned (wiki). Thus, there are two practical rules for us to understand compiler’s padding: Rule 1: any basic data structure/element/variable should be aligned so that their beginning address is divisible (任何变量的开始地址都能被自己的大小整除,即:当被访问的数据长度为 n 字节时,数据地址为 n 字节对齐。). ...