随笔分类 -  C

1
摘要:nasm -f elf -o a.o a.asm gcc -c -m32 -o b.o b.c ld -s -m elf_i386 -Ttext 0x30400 -o b.bin b.o a.o 阅读全文
posted @ 2017-07-15 11:25 tanghuimin0713 阅读(167) 评论(0) 推荐(0)
摘要:一直以为自己对大端小端的区别已经掌握得很清楚了,没想到在实际应用中还是会犯糊涂,这里记录一下,同样的错误不能再犯了。uint32_t temp = 0x01020304;大端:&temp地址处存放的是高字节,即((uint8_t *)&temp)[0] = 0x01;小端:&temp地址处存放的是低... 阅读全文
posted @ 2014-10-11 18:10 tanghuimin0713 阅读(253) 评论(1) 推荐(0)
摘要:题目:http://www.gowrikumar.com/c/参考:http://wangcong.org/blog/archives/291http://www.cppblog.com/smagle/archive/2010/05/27/116211.htmlhttp://blog.chinaun... 阅读全文
posted @ 2014-09-23 22:10 tanghuimin0713 阅读(371) 评论(0) 推荐(0)
摘要:第五十一题Write a C function which does the addition of two integers without using the '+' operator. You can use only the bitwise operators.(Remember the g... 阅读全文
posted @ 2014-09-23 22:01 tanghuimin0713 阅读(302) 评论(0) 推荐(0)
摘要:第四十六题What does the following macro do? #define ROUNDUP(x,n) ((x+n-1)&(~(n-1)))题目讲解:参考:http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=814501用于... 阅读全文
posted @ 2014-09-23 21:51 tanghuimin0713 阅读(561) 评论(0) 推荐(0)
摘要:第三十八题What is the bug in the following program? #include #include #define SIZE 15 int main() { int *a, i; a = malloc(SIZE*sizeof(int... 阅读全文
posted @ 2014-09-23 21:42 tanghuimin0713 阅读(414) 评论(2) 推荐(0)
摘要:第三十四题The following is a piece of C code, whose intention was to print a minus sign 20 times. But you can notice that, it doesn't work. #include in... 阅读全文
posted @ 2014-09-23 21:34 tanghuimin0713 阅读(387) 评论(0) 推荐(0)
摘要:第三十一题The following is a simple C program to read and print an integer. But it is not working properly. What is(are) the mistake(s)? #include int m... 阅读全文
posted @ 2014-09-23 21:28 tanghuimin0713 阅读(437) 评论(0) 推荐(0)
摘要:第二十六题(不会)The following is a simple program which implements a minimal version of banner command available on most *nix systems. Find out the logic use... 阅读全文
posted @ 2014-09-23 07:20 tanghuimin0713 阅读(354) 评论(0) 推荐(0)
摘要:第二十一题What is the potential problem with the following C program? #include int main() { char str[80]; printf("Enter the string:"); ... 阅读全文
posted @ 2014-09-23 07:14 tanghuimin0713 阅读(364) 评论(0) 推荐(0)
摘要:第十六题The following is a small C program split across files. What do you expect the output to be, when both of them compiled together and run?File1.c ... 阅读全文
posted @ 2014-09-23 07:05 tanghuimin0713 阅读(374) 评论(0) 推荐(0)
摘要:第十三题 int CountBits(unsigned int x) { int count=0; while(x) { count++; x = x&(x-1); } return count; }知识点讲... 阅读全文
posted @ 2014-09-23 06:56 tanghuimin0713 阅读(401) 评论(0) 推荐(0)
摘要:第九题#include int main(){ float f=0.0f; int i; for(i=0;i”“int main(){ int a = 1,2; printf("a : %d\n",a); retur... 阅读全文
posted @ 2014-09-23 06:49 tanghuimin0713 阅读(477) 评论(0) 推荐(0)
摘要:第六题 #include int main() { int a=10; switch(a) { case '1': printf("ONE\n"); ... 阅读全文
posted @ 2014-09-23 06:42 tanghuimin0713 阅读(496) 评论(0) 推荐(0)
摘要:第一题 #include #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) int array[] = {23,34,12,17,204,99,16}; int main() { int d; for(d... 阅读全文
posted @ 2014-09-23 06:18 tanghuimin0713 阅读(782) 评论(2) 推荐(0)
摘要:参考文献:《ELF V1.2》《程序员的自我修养---链接、装载与库》第6章 可执行文件的装载与进程 第7章 动态链接《Linux GOT与PLT》开发平台:[root@tanghuimin dynamic_link]# uname -a Linux tanghuimin 2.6.32-358.el... 阅读全文
posted @ 2014-06-08 07:23 tanghuimin0713 阅读(2208) 评论(1) 推荐(1)
摘要:参考文献:《ELF V1.2》《程序员的自我修养---链接、装载与库》第4章 静态链接开发平台:[thm@tanghuimin static_link]$ uname -a Linux tanghuimin 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:... 阅读全文
posted @ 2014-06-08 07:09 tanghuimin0713 阅读(3703) 评论(2) 推荐(2)
摘要:跟atexit函数相识已久,man手册里对atexit的解释是这么一段:The atexit() function registers the given function to be called at normal process termination, either via exit(3) or via return from the program’s main(). Functions so registered are called in the reverse order of their registration; no arguments are passed.乍一看... 阅读全文
posted @ 2014-02-27 20:06 tanghuimin0713 阅读(1513) 评论(0) 推荐(0)
摘要:/linux/include/linux/kernel.h中有min(x, y)和max(x, y)的定义如下: 1 #define min(x, y) ({ \ 2 typeof(x) _min1 = x; \ 3 typeof(y) _min2 = y; \ 4 (void) (&_min1 == &_min2); \ 5 _min1 _max2 ? _max1 : _max2; }红色两行的作用为:防止不同类型的参数进行比较;当参数类型不同时,编译器会提示:warning: comparison of distinct pointer... 阅读全文
posted @ 2013-09-08 12:47 tanghuimin0713 阅读(2015) 评论(2) 推荐(1)
摘要:1 #include 2 3 #define swap_macro_0(a, b) \ 4 do { \ 5 typeof(a) c; \ 6 c = a; \ 7 a = b; \ 8 b = c; \ 9 } while(0)10 11 #define swap_macro_1(a, b) \12 do { \13 a = a + b; \14 b = a - b; \15 a = a - b;... 阅读全文
posted @ 2013-07-28 09:00 tanghuimin0713 阅读(661) 评论(8) 推荐(1)

1