随笔分类 -  C_language

1 2 3 4 下一页

BITCOUNT
摘要:/*****************************************************************************\// returns count of bits reuired to store set of (v) values in range \*... 阅读全文

posted @ 2014-12-11 22:17 阿加

宏定义
摘要:如下:file_one#if !defined(CONFIG_NUMA) || !defined(CONFIG_HAVE_MEMORYLESS_NODES)#ifndef set_numa_mem#define set_numa_mem(node)#endif#ifndef set_cpu_numa... 阅读全文

posted @ 2014-11-29 23:58 阿加

-fomit-frame-pointer
摘要:参考:http://blog.csdn.net/byzs/article/details/2220461为什么会由此记录?读了同事的邮件,看到关于此编译选项的问题,因此做下记录如果发现 %ebp 的值显得不正常,那么可以反汇编,看看%ebp是否被用作帧指针。-fomit-frame-pointer ... 阅读全文

posted @ 2014-10-27 22:55 阿加

glibc eglibc uclibc bionic newlib dietlibc
摘要: 阅读全文

posted @ 2014-02-14 16:37 阿加

空基类优化—— EBCO—— empty base class optimization
摘要:完全参考自:《C++ Templates The Complete Guide》e_CN,p_281 16.2 空基类优化最近周围有点吵,论文没看进去,随便翻了本书……下文没有多大意义,只是解决了自己的一个疑惑。1、为什么C++中不允许类的大小是0class ZeroSizeT {};ZeroSiz... 阅读全文

posted @ 2013-11-28 17:33 阿加 阅读(872) 评论(0) 推荐(0)

如果返回结构体类型变量(named return value optimisation,NRVO) ------ 续
摘要:为什么?《More C++ idioms》: 3. Algebraic Hierarchy程序执行的流程与自己想的不一样: Number Number::makeReal(double r){Number tx; return tx} main: Number t = Number::makeReal(10); 自己想的应该是:先生成tx(默认构造); 返回时需要一个临时量temp,并以tx初始化(拷贝构造),而后用temp初始化 t (拷贝构造); 实际执行流程是:生成tx(默认构造),tx就是t理解好C语言,自然就知道原因了,见:http://www.cnblogs.... 阅读全文

posted @ 2013-11-09 21:17 阿加 阅读(440) 评论(0) 推荐(0)

protected: C++ access control works on per-class basis, not on per-object basis
摘要:一个很简单的问题://为什么BASE::foo()中可以直接通过p访问val? 看本记录标题,这个问题困扰了很长一段时间,终于解决class BASE{ private: int val; public:void foo(BASE *p) { int w = p->val; } };同学参加一场笔试,抛出个问题,丫凡和我讨论了下,丫凡在stackoverflow上找到了答案……如下内容引述自:http://stackoverflow.com/questions/6986798/subtle-c-inheritance-error... 阅读全文

posted @ 2013-09-29 20:07 阿加 阅读(446) 评论(0) 推荐(0)

2013——M笔试南京——程序
摘要:迄今只参加了M南京笔试,可惜自己不是计算机出身,还有好多东西得学啊……M的最后一题是编程:输入:单链表L0、L1、L2……Ln-1、Ln,将链表变为:L0、Ln、L1、Ln-1、L2……算法:1、将链表分成前后两个部分: 前一个链表长度 >= 后一链表长度; 简单2、反转后一个链表; 简单3、合并两个链表; 简单4、调用以上接口; gameover算法实现:typedef struct Node Node_t;Node_t *list_half(Node_t *head){ Node_t *rv = NULL; Node_t *start = he... 阅读全文

posted @ 2013-09-28 13:20 阿加 阅读(562) 评论(0) 推荐(0)

运算符重载
摘要:我们知道如何在遵循C++语法条件下实现"虚函数、重载运算符函数"。我认为当我们尝试来实现重载运算符的虚函数时需要知道:函数签名、redefine、overload、override、虚表、RTTI、编译器默认的插入行为。(此处没有使用虚基类,因此不需要虚表表的知识)和 同学 以及 ”EA娘家人“分别讨论了这个问题,均没有得出详细的解答,不知到android源码中有没有,没仔细找。参考:http://stackoverflow.com/questions/669818/virtual-assignment-operator-chttp://www.icu-project.or 阅读全文

posted @ 2013-08-15 15:08 阿加 阅读(429) 评论(0) 推荐(0)

在C++中实现不可继承的类
摘要:逛下bbs,“在C++中实现不可继承的类”,瞒有意思的。class NoInherite { friend class Seal; private: NoInherite(void) {} ~NoInherite(void) {}};class Seal: virtual private NoInherite{ public: Seal(v... 阅读全文

posted @ 2013-08-11 20:52 阿加 阅读(275) 评论(0) 推荐(0)

How to use base class's assignment operator in C++
摘要:看了android下的代码,好长时间没看了,有个关于C++的知识点不是很清楚,查了下:如何使用基类中的赋值运算符?引述自http://stackoverflow.com/questions/1226634/how-to-use-base-classs-constructors-and-assignment-operator-in-c参考:《C++ Primer》4ed_CN p_495编译器的默认设置:struct base{ base() { std::cout << "base()" << std::endl; } base( base cons 阅读全文

posted @ 2013-08-11 14:19 阿加 阅读(356) 评论(0) 推荐(0)

what's the help of "unnecessary" pointer comparison
摘要:引述自http://c-programming.itags.org/q_c-programming-language_191518.html源代码中的宏min中使用了 (void) (&_x == &_y); ( c89不支持typeof )有如下解释Assuming (as the name "typeof" implies) that _x has the same type asx, and _y has the same type as y, comparing the addresses of _x and _yis legal if and on 阅读全文

posted @ 2013-08-07 14:37 阿加 阅读(324) 评论(0) 推荐(0)

write solid code 零散(原文)
摘要:整理下目录,看了这个文件,幸好未删除。以下是《write solid code》中的原文摘录。1、How could I have prevented this bug?2、How could I have automatically detected this bug?3、If a programmer believes that a bug can simply "go away", or that fixing bugs "later" won't be harmful to the product, bugs will persist.4 阅读全文

posted @ 2013-08-02 08:22 阿加 阅读(273) 评论(0) 推荐(0)

csapp遗留
摘要:再次拜读csapp_2ed,仍然存在大量不足,部分习题尝试做了解答,还是有些不会,一些临碎的记录如下:p_159: sizeof运算符的返回值为size_t,无符号整型; 2.75ANSI C明确规定不允许编译器改变结构体成员对象的次序;如果让编译器随心所欲地改变结构体中各个对象的位置的话,显存的程序大部分都会崩溃。在C语言中,函数往往通过在结构体地址上加上偏移量来计算变量的位置。p_466: ARM中PC为当前指令地址+8通过典型的5级流水显然很容易理解,问题在于mips体系中分支延迟槽的实现问题又一次困扰住自己了(原来看了《计算机组成与设计》,上面讲了,没有留下笔记,有时间还得再看下)p_ 阅读全文

posted @ 2013-08-01 12:19 阿加 阅读(281) 评论(0) 推荐(0)

关于非本地跳转
摘要:csapp p_795如下所述的问题经过讨论并未被解决……以下示例中未以ARM为例,因为我查到的ARM的ABI规范中,寄存器均由callee保存,或者callee与caller均不保存,因此很容易可以解决下列问题。以下以i386为例.关于非本地跳转存在的疑问(以setjmp、longjmp为例)函数调用之间需遵循ABI规范 有些寄存器是由caller保存(以备被callee使用而修改原来的值),当从callee返回后恢复这些寄存器; 有些寄存器是由callee保存(以备被callee使用而修改原来的值),当即将从callee返回时恢复这些寄存器; 某些寄存器可以随便使用,即不需要caller保 阅读全文

posted @ 2013-08-01 12:16 阿加 阅读(460) 评论(0) 推荐(0)

全局变量的多重定义
摘要:此处请参考下:http://coolshell.cn/articles/10115.html C语言全局变量那些事儿csapp :p_700以上记录的解决方法有个缺点,当我们分别编译而后再链接时,只会报warning,因此当我们定义全局变量时尽量使其成为强符号,例如对于上例:double x = 0; 阅读全文

posted @ 2013-08-01 12:13 阿加 阅读(730) 评论(0) 推荐(0)

fstrict-aliasing
摘要:承如“optimization blocks”文中所述,由于相同的指针可能指向相关的内存区,因此编译器将不做过分的优化……特意搜了下编译器在不同的优化等级下都有哪些默认优化,因此有了此记录(比较长,尽管只讲述了fstrict-aliasing ……)下述内容引述自:http://dbp-consulting.com/tutorials/StrictAliasing.html http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html http://stackoverflow.co 阅读全文

posted @ 2013-07-19 22:51 阿加 阅读(4911) 评论(1) 推荐(0)

optimization blocks (csapp chapter 5.1)
摘要:p_511编译器在没有指示下,会做‘ safe optimization',因此有些优化在没有参数的指示下是不会对代码做优化的,故在程序中应该避免某一类代码,因为它们妨碍了编译器做优化。optimization blocks: aspects of programs that can severely limit the opportunities for a compiler to generate optimized code;两类optimization blocks:1、memory aliasing pointers may generate the same memory 阅读全文

posted @ 2013-07-19 22:25 阿加 阅读(320) 评论(0) 推荐(0)

常量和常量表达式
摘要:问题出自于CSAPP:p_105的Web Aside DATA:TMIN#define INT_MAX 2147483647#define INT_MIN (-INT_MAX - 1)文中提出了“为什么INT_MIN 没有直接宏定义为-2147483648 ?"的疑问,但是没有解答。查了下,发现教材中又有一处错了。关于整型常量的定义: “An integer constant begins with a digit, but has no period or exponent part. It may have a prefix that specifies its base and 阅读全文

posted @ 2013-07-12 15:33 阿加 阅读(3077) 评论(0) 推荐(1)

write solid code Chapter 2 练习题4 的解答与扩展
摘要:原题:4、When programmers add new elements to an enumeration, they sometimes forget to add new cases to the appropriate switch statements. How could you use assertions to help detect this problem?附录中的答案:...default: ASSERT(FALSE); /*We should never get here*/ break;把这个问题扩展下:看到上题的时候,想到了在u-boot中加入启动命令... 阅读全文

posted @ 2013-07-10 19:13 阿加 阅读(306) 评论(0) 推荐(0)

1 2 3 4 下一页

导航