易截截图软件、单文件、免安装、纯绿色、仅160KB

关于linux内核中的"__attribute__ ((packed))"

关于linux内核中的"__attribute__ ((packed))"  
来源:
http://jimmy-lee.blog.hexun.com/8001013_d.html
__attrubte__ ((packed)) 的作用就是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐。
#define __u8    unsigned char
#define __u16   unsigned short
/* __attribute__ ((packed)) 的位置约束是放于声明的尾部“;”之前 */
struct str_struct{
        __u8    a;
        __u8    b;
        __u8    c;
        __u16   d;
} __attribute__ ((packed));
/*  当用到typedef时,要特别注意__attribute__ ((packed))放置的位置,相当于:
  *  typedef struct str_stuct str;
  *  而struct str_struct 就是上面的那个结构。
  */
typedef struct {
        __u8    a;
        __u8    b;
        __u8    c;
        __u16   d;
} __attribute__ ((packed)) str;
/* 在下面这个typedef结构中,__attribute__ ((packed))放在结构名str_temp之后,其作用是被忽略的,注意与结构str的区别。*/
typedef struct {
        __u8    a;
        __u8    b;
        __u8    c;
        __u16   d;
}str_temp __attribute__ ((packed));
typedef struct {
        __u8    a;
        __u8    b;
        __u8    c;
        __u16   d;
}str_nopacked;
int main(void)
{
        printf("sizeof str = %d\n", sizeof(str));
      


相关文档:

Linux 的多线程编程的高效开发经验

2009 年 4 月 23 日
本文中我们针对 Linux 上多线程编程的主要特性总结出 5 条经验,用以改善 Linux 多线程编程的习惯和避免其中的开发陷阱。在本文中,我们穿插一些 Windows 的编程用例用以对比 Linux 特性,以加深读者印象。
背景
Linux 平台上的多线程程序开发相对应其他平台(比如 Windows)的多线程 API 有一些细微 ......

Linux指令:chmod

指令名称 : chmod
使用权限 : 所有使用者
使用方式 : chmod [-cfvR] [--help] [--version] mode file...
说明 : Linux/Unix 的档案调用权限分为三级 : 档案拥有者、群组、其他。利用 chmod 可以藉以控制档案如何被他人所调用。
参数 :
mode : 权限设定字串,格式如下 : [ugoa...][[+-=][rwxX] ......

Linux下编译动态库,静态库,以及调用

so_test.h:
#include
#include
void test_a();
void test_b();
void test_c();
test_a.c:
#include "so_test.h"
void test_a()
{
printf("this is in test_a...\n");
}
test_b.c:
#include "so_test.h"
void test_b()
{
printf("this is in test_b...\n");
......

linux常用c函数 文件权限控制篇

access(判断是否具有存取文件的权限)
  相关函数  stat,open,chmod,chown,setuid,setgid
  表头文件  #include<unistd.h>
  定义函数  int access(const char * pathname,int mode);
  函数说明  access()会检查是否可以读/写某一已存在的文件。参数mode有几种情况组合,R_OK ......

移动Linux桌面MeeGo 1.0发布






<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
A:link { so-language: zxx }
-->
    大家知道,
MeeGo
桌面的最大特点是使用自由(
free
use
),不论你在什么地方(什么国家),也不论你想用它干什么事情。那么,
MeeGo
是不是垃圾代码呢?当然不是。 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号