__attribute__ ((attribute-list))
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))的更多相关文章
- Linux 内核使用的 GNU C 扩展
gcc核心扩展linuxforum(转)=========================== Linux 内核使用的 GNU C 扩展 =========================== GNC ...
- GNU C 与 ANSI C的区别
1.零长度数组 GNU C允许使用零长度数组,定义变长度对象时比较方便 struct var_data { int len; char data[0]; }; var_data的大小仅为一个int型, ...
- Linux内核同步
Linux内核剖析 之 内核同步 主要内容 1.内核请求何时以交错(interleave)的方式执行以及交错程度如何. 2.内核所实现的基本同步机制. 3.通常情况下如何使用内核提供的同步机制. 内核 ...
- GNU C 、ANSI C、标准C、标准c++区别和联系
转载自点击打开链接 GNU计划,又称革奴计划,是由Richard Stallman在1983年9月27日公开发起的.它的目标是创建一套完全自由的操作系统.它在编写linux的时候自己制作了一个标准成为 ...
- OC中的__attribute__的使用
简介: 在IOS9.2官方文档中Attributes的描述如下,简单明了: Attributes provide more information about a declaration or typ ...
- 编译器--__attribute__ ((packed))
1. __attribute__ ((packed)) 的作用就是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐,是GCC特有的语法.这个功能是跟操作系统没关系,跟编译器有关,g ...
- iOS宏和__attribute__
本文目录 iOS宏的经典用法 Apple的习惯 __attribute__ iOS宏的经典用法 1.常量宏.表达式宏 #define kTabBarH (49.0f) #define kScreenH ...
- __attribute__
转来的: http://www.cnblogs.com/astwish/p/3460618.html __attribute__ 你知多少? GNU C 的一大特色就是__attribute__ 机制 ...
- __attribute__((packed))作用
1. __attribute__ ((packed)) 的作用就是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐,是GCC特有的语法.这个功能是跟操作系统没关系,跟编译器有关,g ...
- __attribute__((packed))详解
1. __attribute__ ((packed)) 的作用就是告诉编译器取消结构在编译过程中的优化对齐,按照实际占用字节数进行对齐,是GCC特有的语法.这个功能是跟操作系统没关系,跟编译器有关 ...
随机推荐
- tf.metrics.accuracy ==>坑货
tf.metrics.accuracy输出两个值,第一个值为上几步的平均精度,第二值是上几步与该步的精度的平均值. 正常的计算单个batch正确率的代码 self.correct_prediction ...
- 如何从TFS(Visual Studio Team Foundation Server)映射下载本地文件夹
1.连接tfs项目 首先打开vs2017 ——>工具栏 中的 团队——> 选择团队的管理链接 2.选择管理工作区 显示管理工作区的弹窗,点击 编辑 显示弹窗,选择本地文件夹(即要保存 ...
- SpringCloud Config Bus webhook 只能刷新config server 不能刷新config client
在 https://github.com/spring-cloud/spring-cloud-bus/issues/124 中有提到 版本 SpringCloud:Greenwich.RC1 原因 由 ...
- Mac OS 下安装mysqlclient报“mysql_config not found”的解决
如问题所示,应该是你没有将mysql_config所在文件夹加入系统的PATH路径,解决方案下: 1.第一步找到你的mysql_config所在位置 1.1. 如果是直接安装mysql,所在位置应该是 ...
- Python输入/输出
1.在python2.x中raw_input( )和input( ),两个函数都存在,其中区别为 raw_input( )---将所有输入作为字符串看待,返回字符串类型 input( )-----只能 ...
- 【读书笔记】Android平台的漏洞挖掘和分析
最近比较关注移动端的安全,以后也打算向安卓平台的安全发展.这篇博文主要是记录一些研究Android安全的读书笔记. Fuzzing技术的核心是样本生成技术 测试Android平台的组件间通信功能使用的 ...
- InterSystems Ensemble学习笔记(一) Ensemble介绍及安装
系列目录 InterSystems Ensemble学习笔记(一) Ensemble介绍及安装InterSystems Ensemble学习笔记(二) Ensemble创建镜像, 实现自动故障转移 一 ...
- 绝对良心的 Java 中发邮件功能
开篇语,是不是感觉这个功能都老掉牙了,网上一大推的文章,随便找个代码就是了,为什么我还要选择专门写一篇呢,因为我遇到了不一样的坑…… 首先,不免俗套的把代码都贴上来,拿去执行吧,记住换上你的账号和授权 ...
- ONVIF开发实例
<开发过过程中的经验总结> ➤工具的使用 (1)首先将文件soapClientLib.c 中"代码"的第二行和第三行注释掉,实际上该文件根本没有用,为了保险起见 ...
- Xshell6和Xftp下载地址,rzsz的使用
官方下载地址:https://cdn.netsarang.net/98f59c09/Xshell-6.0.0076r_beta.exe https://cdn.netsarang.net/98f59c ...