◄Up► ◄Contents► ◄Index► ◄Back► ─────C/C++ Language───────────────────────────────────────────────────────── Keyword: __segname Syntax: __segname( "segment-name" ) Summary: Specifies the name of a segment. See also: __based, __segment, __self You can declare a based variable by giving it a segment constant as a base. Microsoft C/C++ predefines four segments: Segment Description _CODE Default code segment _CONST Constant segment for strings such as "This is a constant string" _DATA Default data segment _STACK Stack segment The __segname keyword marks the name of a segment. It is always followed by parentheses and a string, as in the example below: // Compile in small model, DOS only #include <stdio.h> #include <malloc.h> char __based( __segname( "_CODE" ) ) mystring[] = "Code-based string.\n"; // Code-based integer: int __based( __segname( "_CODE" ) ) ib = 12345; void main() { printf( "%Fs %d", (char __far *)mystring, ib ); } The mystring variable is declared as an array of characters based in the code segment. The ib variable is an integer (not a pointer) that is also based in the code segment. Note that the small model version of printf would treat mystring as a near pointer. The F in the format specifier %Fs forces the function to treat it as a far pointer, and the cast to (char __far*) coerces the address to four bytes. You also can name your own segments. The declaration of <mystring> might look like this: char __based( __segname( "MYSEGMENT" ) ) mystr[] = "Based string"; In the example above, the compiler creates a new segment called MYSEGMENT and places the string there. Do not use the __segment keyword in a 32-bit program. -♦-