__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特有的语法.这个功能是跟操作系统没关系,跟编译器有关 ...
随机推荐
- 常见四大类型视频接线DP、HDMI、DVI、VGA的比较
如今是新的“视”界,生活中总与各种屏幕打交道,难免会遇到选择视频接线的问题,要想搞清楚这点,我们只要通过了解现今常用的几种视频接线就会有个大致的认识. 281VGA.DVI.HDMI三种视频信号接 ...
- 使用Docker快速搭建sftp服务
一.安装docker环境 参见 http://www.cnblogs.com/rslai/p/8403350.html 二.从Docker Hub查找sftp镜像 docker search sftp ...
- supervisor的安装和配置
1. 安装 yum install supervisor 2.配置 [unix_http_server] file=/tmp/supervisor.sock ;UNIX socket 文件,super ...
- Centos之关机和重启命令
shutdown命令 shutdown [选项] 时间 -c:取消前一个关机命令 -h:关机 -r:重启 [root@localhost ~]# date 2017年 06月 21日 星期三 15:4 ...
- Python学习笔记:bisect模块实现二分搜索
在Python中可以利用bisect模块来实现二分搜索,该模块包含函数只有几个: import bisect L = [1,3,4,5,5,5,8,10] x = 5 bisect.bisect_le ...
- who am i ?
Id:Ox9A82 Email:hucvbty@gmail.com 微博:http://weibo.com/1828621423 知乎:Ox9A82 常乐村男子职业技术学院 Syclover拖后腿成员 ...
- 【58沈剑架构系列】为什么说要搞定微服务架构,先搞定RPC框架?
第一章聊了[“为什么要进行服务化,服务化究竟解决什么问题”] 第二章聊了[“微服务的服务粒度选型”] 今天开始聊一些微服务的实践,第一块,RPC框架的原理及实践,为什么说要搞定微服务架构,先搞定RPC ...
- [翻译]Gulp.js简介
我们讨论了很多关于怎么减少页面体积,提高重网站性能的方法.有些是操作是一劳永逸的,如开启服务器的gzip压缩,使用适当的图片格式,或删除一些不必要的字符.但有一些任务是每次工作都必须反复执行的.如 新 ...
- phpstorm 输入法中文不同步 phpstorm 输入法不跟随光标解决办法
win7系统新安装的phpstorm2017.2版本,试了很多输入法,要么是不显示候选次,要么是输入法候选词总是在屏幕右下角,没有跟随光标移动.百度很久,重要找到解决方案. 就是替换phpstorm安 ...
- 黑马程序员_java基础笔记(03)...面向对象
—————————— ASP.Net+Android+IOS开发..Net培训.期待与您交流!—————————— 1:面向对象的概念,2 : 类和对象的关系,3 : 封装,4 : 构造函数,5 : ...