2013年7月10日

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 阿加 阅读(297) 评论(0) 推荐(0) 编辑

关于write solid code中的memset

摘要: 文中说明memset可以通过操作整形以加速程序执行速度,这一点值得肯定,问题在于unicore或arm中协处理器有地址访问对齐检查,如果我们如此操作,编译器最终使用str指令来完成,那么当地址未对齐时将会出现错误。上次和同学看了下rtems的编译器对于strncpy的实现,由于rtems的编译器本身做了大量优化,当stncpy的拷贝的长度较小时使用了编译器内嵌的实现版本(str完成),而未使用libc库的实现版本(strb),由于使能了地址对齐访问检查,所以程序运行后总是会运行错误。 阅读全文

posted @ 2013-07-10 13:36 阿加 阅读(214) 评论(0) 推荐(0) 编辑

导航