• compiler misc


    compiler misc

    unused attribute

    如果参数/函数没有被使用,可以在参数/函数前加__attribute__ ((unused))

    int main(__attribute__ ((unused)) int argc, __attribute__ ((unused)) char *argv[])

    gcc constructor 与 destructor 属性

    c 代码中使用 gcc attribute((constructor)) 属性修饰的函数,其函数地址将会被放到 init_array section 中,这些函数在 main 函数执行前执行,进行一些必要的初始化工作。

    与之类似的的还有 destructor 属性,这个 destructor 属性修饰的函数会将函数地址放到 fini_array section 中,在 main 函数执行完成后或在 exit 函数中被调用。
    也可以向 constructor 与 destructor 属性修饰的函数指定一个可选的整型优先级。对于 constructor 函数来说小数字对应高优先级,相关的函数优先执行,destructor 正相反。

    from:https://blog.csdn.net/Longyu_wlz/article/details/109128395

    __attribute__((constructor(1))) static void __libc_preinit() {}

    注:0-100是预留的priority,应用可以使用的priority是101-65535

    常用的gcc的__attribute__

    FROM: https://cloud.tencent.com/developer/article/1807134

    good blogs about compiler

    https://www.zhihu.com/people/maskray

  • 相关阅读:
    【Python】【解决】UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 1: ordinal not in range(128)
    【小技巧】强制重启无线网卡,解决“区域中找不到无线网络,请确定您计算机上的无线开关已启用”问题
    【小技巧】9针USB转串口简易连通性测试,附25针转9针
    【ACM】HDU1008 Elevator 新手题前后不同的代码版本
    【Android】命令行jarsigner签字和解决找不到证书链错误
    LeetCode 【47. Permutations II】
    LeetCode 【46. Permutations】
    Python asyncio库的学习和使用
    LeetCode 【190. Reverse Bits】
    LeetCode 【21. Merge Two Sorted Lists】
  • 原文地址:https://www.cnblogs.com/aspirs/p/15810099.html
Copyright © 2020-2023  润新知