Visual Studio 2010
const_seg
Specifies the segment where const variables are stored in the .obj file.
#pragma const_seg( [ [ { push | pop}, ] [ identifier, ] ] [ "segment-name" [, "segment-class" ] )
Remarks
The meaning of the terms segment and section are interchangeable in this topic.
OBJ files can be viewed with the dumpbin application. The default segment in the .obj file for const variables is .rdata. Some const variables, such as scalars, are automatically inlined into the code stream. Inlined code will not appear in .rdata.
const_seg with no parameters resets the segment to .rdata.
Example
// pragma_directive_const_seg.cpp
// compile with: /EHsc
#include <iostream>
const int i = 7; // inlined, not stored in .rdata
const char sz1[]= "test1"; // stored in .rdata
#pragma const_seg(".my_data1")
const char sz2[]= "test2"; // stored in .my_data1
#pragma const_seg(push, stack1, ".my_data2")
const char sz3[]= "test3"; // stored in .my_data2
#pragma const_seg(pop, stack1) // pop stack1 from stack
const char sz4[]= "test4"; // stored in .my_data1
int main() {
using namespace std;
// const data must be referenced to be put in .obj
cout << sz1 << endl;
cout << sz2 << endl;
cout << sz3 << endl;
cout << sz4 << endl;
}
test1 test2 test3 test4
Comments
See /SECTION for a list of names you should not use when creating a section.
You can also specify sections for initialized data (data_seg), uninitialized data (bss_seg), and functions (code_seg).
See Also