http://blog.csdn.net/ithomer/article/details/6566739

构造与析构:

#include <stdio.h>
#include <stdlib.h> static __attribute__((constructor)) void before()
{ printf("Hello");
} static __attribute__((destructor)) void after()
{
printf(" World!\n");
} int main(int args,char ** argv)
{
printf("main");
return EXIT_SUCCESS;
}
~
[root@workstation2017 ~]# ./test.out
Hellomain World!

优先级:

[root@workstation2017 ~]# vi test.c

#include <stdio.h>
#include <stdlib.h> static __attribute__((constructor())) void begin101()
{ printf("Hello-101\n");
} static __attribute__((constructor())) void begin102()
{ printf("Hello-102\n");
} static __attribute__((destructor())) void end101()
{
printf(" World!-101\n");
} static __attribute__((destructor())) void end102()
{
printf(" World!-102\n");
} int main(int args,char ** argv)
{ return EXIT_SUCCESS;
}
[root@workstation2017 ~]# ./test.out
Hello-
Hello-
World!-
World!-

对齐属性:

__attrubte__ ((packed)) 的作用就是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐

[root@workstation2017 ~]# vi test.c

#include <stdio.h>
#include <stdlib.h>
#define __u8 unsigned char
#define __u16 unsigned short struct str_struct{
__u8 a;
__u8 b;
__u8 c;
__u16 d;
} __attribute__ ((packed)); typedef struct {
__u8 a;
__u8 b;
__u8 c;
__u16 d;
} __attribute__ ((packed)) 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));
printf("sizeof str_struct = %d\n", sizeof(struct str_struct));
printf("sizeof str_temp = %d\n", sizeof(str_temp));
printf("sizeof str_nopacked = %d\n", sizeof(str_nopacked));
return ;
}
[root@workstation2017 ~]# ./test.xx
sizeof str =
sizeof str_struct =
sizeof str_temp =
sizeof str_nopacked =

变量占内存大小 x64 x32差别:

 变量的长度,在不同的系统之间会有差别,64位Linux系统和32位Linux系统中,几种常见C语言变 量的长度:
short int long long long ptr time_t
32位
64位

__attribute__ ((attribute-list))的更多相关文章

  1. Linux 内核使用的 GNU C 扩展

    gcc核心扩展linuxforum(转)=========================== Linux 内核使用的 GNU C 扩展 =========================== GNC ...

  2. GNU C 与 ANSI C的区别

    1.零长度数组 GNU C允许使用零长度数组,定义变长度对象时比较方便 struct var_data { int len; char data[0]; }; var_data的大小仅为一个int型, ...

  3. Linux内核同步

    Linux内核剖析 之 内核同步 主要内容 1.内核请求何时以交错(interleave)的方式执行以及交错程度如何. 2.内核所实现的基本同步机制. 3.通常情况下如何使用内核提供的同步机制. 内核 ...

  4. GNU C 、ANSI C、标准C、标准c++区别和联系

    转载自点击打开链接 GNU计划,又称革奴计划,是由Richard Stallman在1983年9月27日公开发起的.它的目标是创建一套完全自由的操作系统.它在编写linux的时候自己制作了一个标准成为 ...

  5. OC中的__attribute__的使用

    简介: 在IOS9.2官方文档中Attributes的描述如下,简单明了: Attributes provide more information about a declaration or typ ...

  6. 编译器--__attribute__ ((packed))

    1. __attribute__ ((packed)) 的作用就是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐,是GCC特有的语法.这个功能是跟操作系统没关系,跟编译器有关,g ...

  7. iOS宏和__attribute__

    本文目录 iOS宏的经典用法 Apple的习惯 __attribute__ iOS宏的经典用法 1.常量宏.表达式宏 #define kTabBarH (49.0f) #define kScreenH ...

  8. __attribute__

    转来的: http://www.cnblogs.com/astwish/p/3460618.html __attribute__ 你知多少? GNU C 的一大特色就是__attribute__ 机制 ...

  9. __attribute__((packed))作用

    1. __attribute__ ((packed)) 的作用就是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐,是GCC特有的语法.这个功能是跟操作系统没关系,跟编译器有关,g ...

  10. __attribute__((packed))详解

      1. __attribute__ ((packed)) 的作用就是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐,是GCC特有的语法.这个功能是跟操作系统没关系,跟编译器有关 ...

随机推荐

  1. python_接口自动化测试框架

    本文总结分享介绍接口测试框架开发,环境使用python3+selenium3+unittest+ddt+requests测试框架及ddt数据驱动,采用Excel管理测试用例等集成测试数据功能,以及使用 ...

  2. MS Sql Server 数据库或表修复(DBCC CHECKDB)

    MS Sql Server 提供了很多数据库修复的命令,当数据库质疑或是有的无法完成读取时可以尝试这些修复命令.  1. DBCC CHECKDB  重启服务器后,在没有进行任何操作的情况下,在SQL ...

  3. vue组件中的轮播实现

    一.直接上代码 <template> <el-row class="Slide"> <el-row class="title"&g ...

  4. MySQL学习笔记:set autocommit=0和start transaction

    在MySQL中,接触事务的例子比较少,今晚在一个简单的存储过程中,循环插入50000条id数据的时候,得知必须开事务,如果逐提交数据,将会导致速度异常的慢. SET autocommit = 0;   ...

  5. Python之Selenium的爬虫用法

    Selenium 2,又名 WebDriver,它的主要新功能是集成了 Selenium 1.0 以及 WebDriver(WebDriver 曾经是 Selenium 的竞争对手).也就是说 Sel ...

  6. Sourcetree使用 - git图形化工具(三)

    前面两个章节总结了Sourcetree的安装与配置Sourcetree密钥,这个章节主要讲如何使用Sourcetree.以前呢,都是使用git Bash进行命令行方式进行操作git,感觉部分时间浪费在 ...

  7. 配置JDK-Java运行环境

    1.将Java安装包上传到服务器某目录,如E:\jdk-7u45-windows-x64.exe 2.上传后运行jdk-7u45-windows-x64.exe 3.点击[下一步],后选择[更改],改 ...

  8. Hive(三)Hive元数据信息对应MySQL数据库表

    概述 Hive 的元数据信息通常存储在关系型数据库中,常用MySQL数据库作为元数据库管理.上一篇hive的安装也是将元数据信息存放在MySQL数据库中. Hive的元数据信息在MySQL数据中有57 ...

  9. linux ncat命令

    netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据.通过与其他工具结合和重定向,你可以在脚本中以多种方式使用它.使用netcat命令所能完成的事情令人惊讶. netcat所做的 ...

  10. 教你如何清除 MyEclipse/Eclipse 中 Web Browser 和 Switch Workspace 的历史记录

    有些许强迫症的开发人员可能会因为 MyEclipse/Eclipse 中 Web Browser 和 Switch Workspace 冗余的历史记录而感到苦恼,下面的方法就可以有效的帮助解决你的痛点 ...