Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of "#pragma section <XYZ>" in C?

Tags:

c

pragma

What is the use of "#pragma section <XYZ>" in C ?

I have come across C code file where the following kind was used:-

#define XYZ "ITEM 26.G03"

#pragma section <XYZ>

where XYZ is: #define XYZ "ITEM 26.G03"

I need some explaination on the use of "#pragma section"

like image 359
user1074836 Avatar asked Aug 16 '12 06:08

user1074836


People also ask

What is a use of for?

We use for to talk about a purpose or a reason for something: I'm going for some breakfast. I'm really hungry. She leaves on Friday for a 15-day cruise around the Mediterranean. I wear these old trousers for painting.

What's the use of examples?

Examples help you clarify complex concepts, even in regulations. They are an ideal way to help your readers. In spoken English, when you ask for clarification of something, people often respond by giving you an example. Good examples can substitute for long explanations.

What is the use of phrase?

A phrase is a small group of words that communicates a concept but isn't a full sentence. You use phrases in your writing and your speech every day. There are lots of different kinds of phrases, some of which play a technical role in your writing and others that play a more illustrative role.

What is the use of @after?

After as a preposition and conjunction After can be used before a noun phrase (as a preposition): Shall we have a swim after lunch? The bank is just after the park, on the left. After can introduce a clause (as a conjunction):


2 Answers

The #pragma directive is an implementation specific directive it is a standard way to provide additional information to the compiler. This directive has the following form:

#pragma name

If the preprocessor recognizes the specified "name", it performs whatever action they stand for, or passes information on to the compiler. If "name" is not supported by the c implementation it's ignored.

For example gcc compiler accept the list of pragmas listed here.

For the #pragma section, the documentation of gcc said:

section ("section-name") Normally, the compiler places the code it generates in the text section. Sometimes, however, you need additional sections, or you need certain particular functions to appear in special sections. The section attribute specifies that a function lives in a particular section. For example, the declaration:

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

puts the function foobar in the bar section.

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.

More on that here.

like image 56
TOC Avatar answered Oct 13 '22 12:10

TOC


Section creates a section in an .obj file.
Refer to MSDN for more details.

Code and data are generated in sections in an object file, combined by the linker into an executable file, and ultimately located in target memory at specific locations. Default sections are predefined and have certain attributes. The section pragmas may be used to change the default attributes, to define new sections, and to control the assignment of code and variables to particular sections and, along with the linker command file, their locations.

#pragma section defines a section class, and optionally, one or two sections in the class. A section class controls the addressing and accessibility of variables and code placed in an instance of the class.

like image 25
Jainendra Avatar answered Oct 13 '22 10:10

Jainendra