2013年7月29日

关于malloc(0)的返回值问题--这两天的总结与实践篇

摘要: 就像我在http://www.cnblogs.com/wuyuegb2312/p/3219659.html文章中评论的那样,我也碰到了被提问这个malloc(0)的返回值问题,虽然感觉这样做在实际中没有任何意义,但既然被提问到了,那总得给点答复。当时的回答是“返回一个NULL指针”。就像@五岳查看man结果的一样,我也查看了,malloc() allocatessizebytes and returns a pointer to the allocated memory. The memory is notcleared. Ifsizeis 0, then malloc() returns e 阅读全文

posted @ 2013-07-29 13:00 净坛使者 阅读(25084) 评论(47) 推荐(5) 编辑

2013年7月28日

<转载>gcc/g++编译

摘要: 转载于:http://www.cnblogs.com/yc_sunniwell/archive/2010/07/22/1782678.html1. gcc/g++在执行编译工作的时候,总共需要4步(1).预处理,生成.i的文件[预处理器cpp](2).将预处理后的文件不转换成汇编语言,生成文件.s[编译器egcs](3).有汇编变为目标代码(机器代码)生成.o的文件[汇编器as](4).连接目标代码,生成可执行程序[链接器ld][参数详解]-x language filename 设定文件所使用的语言,使后缀名无效,对以后的多个有效.也就是根据约定C语言的后缀名称是.c的,而C++的后缀名.. 阅读全文

posted @ 2013-07-28 19:45 净坛使者 阅读(430) 评论(0) 推荐(0) 编辑

<转载>浅谈C/C++的浮点数在内存中的存储方式

摘要: C/C++浮点数在内存中的存储方式 任何数据在内存中都是以二进制的形式存储的,例如一个short型数据1156,其二进制表示形式为00000100 10000100。则在Intel CPU架构的系统中,存放方式为 10000100(低地址单元) 00000100(高地址单元),因为Intel CPU的架构是小端模式。但是对于浮点数在内存是如何存储的?目前所有的C/C++编译器都是采用IEEE所制定的标准浮点格式,即二进制科学表示法。 在二进制科学表示法中,S=M*2^N 主要由三部分构成:符号位+阶码(N)+尾数(M)。对于float型数据,其二进制有32位,其中符号位1位,阶码8位,尾数23 阅读全文

posted @ 2013-07-28 15:52 净坛使者 阅读(272) 评论(5) 推荐(0) 编辑

2013年7月26日

fedora 16安装ByPass四网口网卡遇到的问题

摘要: 这个问题困扰了好几天,今天终于在大谷歌的帮助下,在这个网站http://blog.bwysystems.com/bwysystems/?p=16上找到了答案!还是国外的技术论坛强,在百度上搜遍了也没有找到这篇文章,下面简单叙述整个安装过程。1. 安装e1000e驱动。1. Move the base driver tar file to the directory of your choice. For example, use /home/username/e1000e or /usr/local/src/e1000e.2. Untar/unzip archive: tar z... 阅读全文

posted @ 2013-07-26 10:56 净坛使者 阅读(963) 评论(0) 推荐(0) 编辑

<一道题>abc+cba=1333,求满足条件的abc的值,隐含条件a!=0,c!=0

摘要: 这类东西,无非就是穷举法。见下面代码:#include #include /**abc + cba = 1333 **a = ?*b = ?*c = ?*/int main(int argc ,char **argv){ int a=0; int b=0; int c=0; int index = 0; printf("abc + cba == 1333\n"); for(a = 1 ; a <= 9 ; a++)//a [1,9] { for(b = 0 ; b <= 9; b++)//b [0,9] { ... 阅读全文

posted @ 2013-07-26 09:46 净坛使者 阅读(953) 评论(2) 推荐(0) 编辑

2013年7月25日

<一道题>求1 + 2! + 3! + .... + N!

摘要: 一道小题,╮(╯▽╰)╭#include /*jie cheng** 1 + 2! + 3! + ... + N!***/int factorial(int val){ if(val > 1) { //printf("val %d\t",val); return val*factorial(val - 1); } else if(val == 1) { return 1; } }int main(int argc, char **argv){ int val = 0; printf("ple... 阅读全文

posted @ 2013-07-25 15:52 净坛使者 阅读(257) 评论(7) 推荐(0) 编辑

2013年7月24日

<系统函数实现>memcmp

摘要: 这是我实现的memcmp函数: 1 #include 2 #include 3 /* 4 *int memcmp (const void *s1,const void *s2,size_t n); 5 *º¯Êý˵Ã÷ 6 *memcmp()ÓÃÀ´±È½Ïs1ºÍs2ËùÖ¸µÄÄÚ´æÇø&# 阅读全文

posted @ 2013-07-24 15:00 净坛使者 阅读(817) 评论(0) 推荐(0) 编辑

2013年7月19日

Shell 脚本基本操作练习

摘要: 这里主要是熟悉了shell的基本操作,包括变量赋值引用修改、函数的使用、信号的获取及一些判断方法等,具体详见代码:#!/bin/shstr="Hello World !"echo "${str}aha"#''echo '$str'#file nameecho "the name of this shell script is $0"#first parameter , $1---$Necho "the first parameter is $1"#all of the paramet 阅读全文

posted @ 2013-07-19 16:30 净坛使者 阅读(831) 评论(0) 推荐(1) 编辑

Unix 环境高级编程---线程创建、同步、

摘要: 一下代码主要实现了linux下线程创建的基本方法,这些都是使用默认属性的。以后有机会再探讨自定义属性的情况。主要是为了练习三种基本的线程同步方法:互斥、读写锁以及条件变量。#include #include #include #include int g_count = 0;pthread_mutex_t mutex_lock;pthread_rwlock_t rw_lock;pthread_cond_t con_val = PTHREAD_COND_INITIALIZER;typedef enum { MutexLock = 0, RWLock, CondLock}Lock... 阅读全文

posted @ 2013-07-19 13:42 净坛使者 阅读(786) 评论(2) 推荐(0) 编辑

2013年7月12日

ubuntu 安装ssh-server时出现错误:openssh-server: Depends: openssh-client (= 1:5.3p1-3ubuntu3) but 1:5.3p1-3ubuntu4 is to be installed

摘要: 错误如下:tiger@ubuntu:~/Desktop/work$ sudo apt-get install openssh-server [sudo] password for tiger: Reading package lists... DoneBuilding dependency tree Reading state information... DoneSome packages could not be installed. This may mean that you haverequested an impossible situation or if you a... 阅读全文

posted @ 2013-07-12 09:51 净坛使者 阅读(8417) 评论(0) 推荐(0) 编辑

导航