define a program section in C code (GCC)

前端 未结 1 734
执笔经年
执笔经年 2020-12-03 22:06

In assembly language, it\'s easy to define a section like:

.section foo

How can this be done in C code? I want to put a piece of C code in

相关标签:
1条回答
  • The C standard doesn't say anything about "sections" in the sense that you mean, so you'll need to use extensions specific to your compiler.

    With GCC, you will want to use the section attribute:

    extern void foobar(void) __attribute__((section("bar")));
    

    There is some limited documentation here, including a warning:

    Some file formats do not support arbitrary sections so the section attribute is not available on all platforms. If you need to map the entire contents of a module to a particular section, consider using the facilities of the linker instead.

    0 讨论(0)
提交回复
热议问题