Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
880 views
in Technique[技术] by (71.8m points)

c - What is the use of pragma code section and data section?

What exactly will happen to the data segment and text segment if I use the below two lines in my c source code file?

#pragma CODE_SECTION(func1, "Sec1")
#pragma DATA_SECTION(globalvar1, "Sec2")
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Source (contains examples): https://web.archive.org/web/20080803190119/http://hi.baidu.com/jevidyang/blog/item/6d4dc436d87e3a300b55a918.html

Note: #pragma is compiler specific, so syntax may vary for your compiler.

The DATA_SECTION pragma allocates space for the symbol in a section called section name. The syntax for the pragma in C could be:

#pragma DATA_SECTION (symbol, "section name");

The syntax for the pragma in C++ could be:

#pragma DATA_SECTION ("section name");

The DATA_SECTION pragma is useful if you have data objects that you want to link into an area separate from the .bss section.


The CODE_SECTION pragma allocates space for the func in a section named section name. The CODE_SECTION pragma is useful if you have code objects that you want to link into an area separate from the .text section. The syntax of the pragma in C could be:

#pragma CODE_SECTION (func, "section name")

The syntax of the pragma in C++ could be:

#pragma CODE_SECTION ("section name")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...