摘要: //原文链接:http://graphics.stanford.edu/~seander/bithacks.html Individually, the code snippets here are in the public domain (unless otherwise noted) — feel free to use them however you please. The aggreg... 阅读全文
posted @ 2013-09-21 22:40 Pianistx 阅读(217) 评论(0) 推荐(0) 编辑
摘要: C++ExpertsForumTheStandardLibrarian:I/OandFunctionObjects:ContainersofPointersMatthewAusternLikemostoftheStandardC++library,thestandardcontainerclassesareparameterizedbytype:youcancreateanstd::vectortoholdobjectsoftypeint,anstd::vectortoholdstringobjects,andanstd::vectortoholdobjectsofsomeuser-defin 阅读全文
posted @ 2013-09-20 15:13 Pianistx 阅读(244) 评论(0) 推荐(0) 编辑
摘要: 就我自己的理解,谈谈我对读研和软件学院的看法,不妥之处一笑了之即可。 如果你有实际开发工作经验,感觉自己的水平和实力进入了一个高原期,迫切需要从理论上提高,那么计算机学院是唯一选择。因为计算机学院才能让你在理论上更上一层楼。软件学院从教学计划上就没有把你往这方面带。当然能不能更上一层楼最终还是完全取决于你自己。需要特别说明的是,工作经验并不一定等于开发经验,我见过很多工作2-3年的人,但是... 阅读全文
posted @ 2013-09-15 22:01 Pianistx 阅读(340) 评论(0) 推荐(0) 编辑
摘要: 学习高效编程的有效途径之一就是阅读高手写的源代码,CRT(C/C++ Runtime Library)作为底层的函数库,实现必然高效。恰好手中就有glibc和VC的CRT源代码,于是挑了一个相对简单的函数strlen研究了一下,并对各种实现作了简单的效率测试。 strlen的函数原形如下: size_t strlen(const char *str); strlen返... 阅读全文
posted @ 2013-09-15 00:44 Pianistx 阅读(1850) 评论(6) 推荐(2) 编辑
摘要: 研究printf的实现,首先来看看printf函数的函数体 int printf(const char *fmt, ...) { int i; char buf[256]; va_list arg = (va_list)((char*)(&fmt) + 4); i = vsprintf(buf, fmt, arg); ... 阅读全文
posted @ 2013-09-11 22:15 Pianistx 阅读(12202) 评论(0) 推荐(3) 编辑
摘要: C++ 中的枚举类型继承于 C 语言。就像其他从 C 语言继承过来的很多特性一样,C++ 枚举也有缺点,这其中最显著的莫过于作用域问题——在枚举类型中定义的常量,属于定义枚举的作用域,而不属于这个枚举类型。例如下面的示例: enum FileAccess { Read = 0x1, Write = 0x2, }; FileAccess access = ::Re... 阅读全文
posted @ 2013-08-28 00:54 Pianistx 阅读(2189) 评论(0) 推荐(0) 编辑
摘要: 在Linux内核、嵌入式代码等传统的C代码里,会有一些难以识别的宏定义。我记得在eCos, UBoot, FFmpeg有一些比较BT的宏定义,很难读懂。对于C++程序员来说,最好将这种难读的宏定义转成inline函数或模板函数。本章对这些较难的重定义进行汇总。 1. ; 在宏定义中指定义类型参数 1: #define FPOS_TO_VAR(fpos, typed, va... 阅读全文
posted @ 2013-08-28 00:52 Pianistx 阅读(374) 评论(0) 推荐(0) 编辑
摘要: 浮点数的编码转换采用的是IEEE规定的编码标准,float和double 这两种类型的数据的转换原理相同,但是由于范围不一样,编码方式有些区别。IEEE规定的编码会将一个浮点数转换为二进制数。以科学计数法划分,将浮点数拆分成3部分:符号,指数,尾数。 1. float类型的IEEE编码。 Float类型在内存中占4个字节(32位)。最高位用于表示符号:剩余31位中,从右向左取8位表示用于指数,... 阅读全文
posted @ 2013-08-28 00:40 Pianistx 阅读(2038) 评论(0) 推荐(0) 编辑
摘要: Memory management is the heart of operating systems; it is crucial for both programming and system administration. In the next few posts I’ll cover memory with an eye towards practical aspects, but wi... 阅读全文
posted @ 2013-08-28 00:31 Pianistx 阅读(180) 评论(0) 推荐(0) 编辑
摘要: Previously we looked at how the kernel manages virtual memory for a user process, but files and I/O were left out. This post covers the important and often misunderstood relationship between files and... 阅读全文
posted @ 2013-08-28 00:29 Pianistx 阅读(274) 评论(0) 推荐(0) 编辑