摘要: 在<netinet/in.h>中声明了IPV4的地址结构struct in_addr{ in_addr_t s_addr; //32bit};struct sockaddr_in{ uint8_t sin_len; sa_family_t sa_family; in_port_t sin_port; struct in_addr sin_addr; char sin_zero[8];};结构总大小至少 16 字节sockeaddr_in serv;serv.sin_addr 引用 in_addr 结构se... 阅读全文
posted @ 2012-10-15 23:00 khalil 阅读(98) 评论(0) 推荐(0) 编辑
摘要: 什么是内存补齐?简言之,就是各种复合数据结构(如class, struct, union,array 等)依照其最大的成员类型字节数进行补齐。首先,各数据成员依据自身类型大小分别进行不齐,最后,复合数据结构再根据最大的类型补齐。如下:struct test{ char a; int b; short c; double d;};sizeof(test) = ?首先,a为1个字节,其自然对齐码为1, b为4个字节,自然对起码为4, 所以a后面需要填充3个空白字符, 同理,c自然对齐码为2, d为8,所以,分别填充0个,6个空白字符,再加上d,总共为24个字符,最后,因为test结构中最大... 阅读全文
posted @ 2012-10-05 18:08 khalil 阅读(409) 评论(0) 推荐(0) 编辑
摘要: APUE第三章的一个习题,分享一下 1 #include <stdio.h> 2 #include <string.h> 3 #include <fcntl.h> 4 #include <unistd.h> 5 #include <errno.h> 6 7 #define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) 8 9 int mydup2 (int oldfile, int newfile) {10 int tempfile;11 if ((tempfile = dup(o 阅读全文
posted @ 2012-10-03 16:51 khalil 阅读(229) 评论(0) 推荐(0) 编辑
摘要: 杂记: 1、指针是一个类型,数组是一个数据结构。 2、数组名可以转换为指向其第一个元素的常量指针。 3、当数组作为函数参数,其实参化为非常量指针。 阅读全文
posted @ 2012-10-03 08:48 khalil 阅读(91) 评论(0) 推荐(0) 编辑