Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
_segname
◄Up► ◄Contents► ◄Index► ◄Back►
────────────────────────────────────────────────────────────────────────────
Keyword: _segname
Syntax: _segname ( "segment-name" )
Summary: Specifies the name of a segment.
See also: _based, _segment, _self
One way to declare a based variable is to give it a segment
constant as a base. Four segments are predefined in Microsoft C:
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";
int _based( _segname( "_CODE" ) )ib = 12345;// Code-based integer
void main()
{
printf( "%Fs %d", (char _far *)mystring, ib );
}
The variable <mystring> is declared as an array of characters
based in the code segment. The variable <ib> 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 can also 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.
-♦-