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 a special section rather than .text
, so I will be able to put that section in a special location in the linker script.
I'm using GCC.
Definition section − Here, variables are defined and initialised. Global declaration section − In this section, global variables are defined which can be used throughout the program. Function prototype declaration section − This section gives information like return type, parameters, names used inside the function.
gcc performs the compilation step to build a program, and then it calls other programs to assemble the program and to link the program's component parts into an executable program that you can run.
When referring to HTML, a section is an area in the web page containing specific programming, text, or images that are separated from other areas using certain HTML tags.
gcc is used to compile C program. g++ can compile any . c or . cpp files but they will be treated as C++ files only.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With