⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcptrs.gml

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 GML
📖 第 1 页 / 共 2 页
字号:
objects. However, when either the big code or big data model
is being used, the keyword
.kwix &kwnear_sp.
.kwfont &kwnear.
may be used to override to the small model.
.pp
The
.kwix &kwnear_sp.
.kwfont &kwnear.
keyword
is a type qualifier that modifies the token that follows it.
If
.kwix &kwnear_sp.
.kwfont &kwnear.
precedes
.mono *
(as in
.mono &kwnear. *
..ct ),
then the pointer points to something near. Otherwise, if
.kwix &kwnear_sp.
.kwfont &kwnear.
precedes the identifier of the object or function being declared
(as in
.mono &kwnear. x)
..ct ,
then the object itself is near.
.pp
The keyword
.kwix &kwnear_sp.
.kwfont &kwnear.
can only be applied to function and object names
and the indirection (pointer) symbol
.mono *.
.shade begin
&wc286. provides the predefined macros
.mkw near
and
.mkw _near
for convenience and compatibility with the Microsoft C compiler.
They may be used in place of
.kwix &kwnear_sp.
.kwfont &kwnear.
..ct ..li .
.shade end
.pp
The following examples illustrate the use of the
.kwix &kwnear_sp.
.kwfont &kwnear.
keyword.
These examples assume that the large memory module
(big code, big data)
is being used.
.millust begin
extern int &kwnear. * x;
.millust end
.discuss begin
declares the object
.mono x
to be a pointer to a near integer.
(
..ct .mono x
is not necessarily
within the 64K data area that is near, but the integer that it
points to is.)
.discuss end
.millust begin
extern int * &kwnear. nx;
.millust end
.discuss begin
declares the object
.mono nx
to be near, and is a pointer to a far integer.
(
..ct .mono nx
is within the 64K data area that is near, but the integer that it
points to might not be.)
.discuss end
.millust begin
extern int &kwnear. * &kwnear. nnx;
.millust end
.discuss begin
declares the object
.mono nnx
to be near, and is a pointer to a near integer.
(
..ct .mono nnx
and the integer that it points to are both within the 64K data area
that is near.)
.discuss end
.millust begin
struct symbol * &kwnear. NSymAlloc( void );
.millust end
.discuss begin
declares the function
.mono NSymAlloc
to be near, and returns a pointer to a far
.mono symbol
structure.
.discuss end
.keep begin
.millust begin
struct symbol &kwnear. * &kwnear. NNSymAlloc( void );
.millust end
.discuss begin
declares the function
.mono NNSymAlloc
to be near, and returns a pointer to a near
.mono symbol
structure.
.discuss end
.keep end
.*
.section &hugekw. for &wc286.
.*
.ix pointer huge
.ix 'huge pointer'
.pp
Even using the big data model, each object is restricted in size
to 64K.
Some applications will need to get beyond this limitation.
The &wc286. compiler provides the keyword
.kwix &kwhuge_sp.
.kwfont &kwhuge.
to describe those objects that exceed 64K in size. The code generated
for these objects is less efficient than for
.kwix &kwfar_sp.
.kwfont &kwfar.
objects.
.pp
The declaration of such objects follows the same pattern as above, with
the keyword
.kwix &kwhuge_sp.
.kwfont &kwhuge.
preceding the name of the object if the object itself is bigger than
64K, or preceding the
.mono *
if the pointer is to an object that is bigger than 64K.
.pp
The keyword
.kwix &kwhuge_sp.
.kwfont &kwhuge.
can only be applied to arrays.
Huge objects may be used in both the small and big data models.
.shade begin
&wc286. provides the predefined macros
.mkw huge
and
.mkw _huge
for convenience and compatibility with the Microsoft C compiler.
They may be used in place of
.kwix &kwhuge_sp.
.kwfont &kwhuge.
..ct ..li .
.shade end
.pp
These examples illustrate the use of the
.kwix &kwhuge_sp.
.kwfont &kwhuge.
keyword. They assume that big code, small data
.ix 'memory model' 'medium'
.ix 'medium memory model'
(the medium memory model) is in effect.
.millust begin
int &kwhuge. iarray[50000];
.millust end
.discuss begin
declares the object
.mono iarray
to be an array of 50000 integers, for a total size of 100000 bytes.
.discuss end
.millust begin
int &kwhuge. * iptr;
.millust end
.discuss begin
declares
.mono iptr
to be near, and a pointer to an integer that is part of a huge array,
such as an element of
.mono iarray.
.discuss end
.endlevel
.*
.section &ptr386.
.*
.pp
With an 80386 processor in "protect" mode,
a normal pointer (32 bits) can point to
a 4 gigabyte (4,294,967,296 byte) region of the memory available
on the machine.
(In practice, memory limits may mean that these regions will be
smaller than 4 gigabytes.)
These regions are called
.us segments,
and
there may be more than one
segment
defined for the memory.
Each 32-bit pointer is actually an offset within a 4 gigabyte segment,
and the offsets within two different segments are generally not related
to each other in a known manner.
.pp
As an example, the screen memory may be set up so that it resides in a
different region of the memory from the program's data.
Normal pointers (those within the program's data area)
will not be able to access such regions.
.pp
Like the 16-bit version of &wcgeneric. (for the 8086 and 80286),
&wc386. uses the
.kwix &kwnear_sp.
.kwfont &kwnear.
and
.kwix &kwfar_sp.
.kwfont &kwfar.
keywords to describe objects that are either in the normal data space
or elsewhere.
.pp
Objects or functions that are near require a 32-bit pointer to access them.
.pp
Objects or functions that are far require a 48-bit pointer to access them.
This 48-bit pointer consists of two parts:
a
.ix pointer selector
.ul selector
consisting of 16 bits,
and an
.ix pointer offset
.ul offset
consisting of 32 bits.
A selector is similar to a segment in a 16-bit program's far pointer,
except that the numeric value of the selector does not directly determine
the memory region.
Instead, the processor uses the selector value in conjunction with a
"descriptor table" to determine what region of memory is to be
accessed.
In the discussion of far pointers on the 80386, the terms
.ix pointer selector
selector and
.ix pointer segment
segment may be used interchangeably.
.pp
Like the 16-bit compiler, the &wc386. compiler supports the
.ix 'memory model' 'small'
.ix 'small memory model'
small,
.ix 'memory model' 'compact'
.ix 'compact memory model'
compact,
.ix 'memory model' 'medium'
.ix 'medium memory model'
medium and
.ix 'memory model' 'large'
.ix 'large memory model'
large memory models.
Throughout the discussions in the following sections, it is assumed
that the small memory model is being used, since it is the most likely
to be used.
.*
.beglevel
.section The &kwfar_sp. Keyword for &wc386.
.*
.pp
The
.kwix &kwfar_sp.
.kwfont &kwfar.
keyword is a type qualifier that modifies the token that follows it.
If
.kwix &kwfar_sp.
.kwfont &kwfar.
precedes
.mono *
(as in
.mono &kwfar. *
..ct ), then the pointer points to something that is far (not in the
normal data region).
Otherwise, if
.kwix &kwfar_sp.
.kwfont &kwfar.
precedes the identifier of the object or function being declared (as in
.mono &kwfar. x
..ct ), then the object or function is far.
.pp
The keyword
.kwix &kwfar_sp.
.kwfont &kwfar.
can only be applied to function and object names and the
indirection (pointer) symbol
.mono *
..ct ..li .
Parameters to functions may
.us not
be declared as
.kwix &kwfar_sp.
.kwfont &kwfar.
..ct , since they are always in the normal data region.
.pp
These examples illustrate the use of the
.kwix &kwfar_sp.
.kwfont &kwfar.
keyword, and assume that the small memory model is being used.
.millust begin
int &kwfar. * ptr;
.millust end
.discuss begin
declares
.mono ptr
to be a pointer to an integer.
The object
.mono ptr
is near
but the integer that it points to is far.
.discuss end
.millust begin
int * &kwfar. fptr;
.millust end
.discuss begin
also declares
.mono fptr
to be a pointer to an integer.
However, the object
.mono fptr
is far, but the integer that it points to is near.
.discuss end
.millust begin
int &kwfar. * &kwfar. ffptr;
.millust end
.discuss begin
declares
.mono ffptr
to be a pointer (which is far) to an integer (which is far).
.discuss end
.pp
When declaring a function, placing the keyword
.kwix &kwfar_sp.
.kwfont &kwfar.
in front of the function name causes the compiler to treat the function
as being far. It is important, if the function is called before its
definition, that a
.ix 'function' 'prototype'
.us function prototype
be included prior to any calls.
For example, the declaration,
.millust begin
extern void &kwfar. SystemService();
.millust end
.pc
declares the function
.mono SystemService
to be far, meaning that any calls to it must be far calls.
.keep begin
.pp
Here are a few more examples:
.millust begin
extern struct systbl * &kwfar. FSysTblPtr( void );
.millust end
.discuss begin
declares the function
.mono FSysTblPtr
to be far, returning a pointer to a near
.mono systbl
structure.
.discuss end
.keep break
.millust begin
extern struct systbl &kwfar. * &kwfar. FFSysTblPtr( void );
.millust end
.discuss begin
declares the function
.mono FFSysTblPtr
to be far, returning a pointer to a far
.mono systbl
structure.
.discuss end
.keep break
.millust begin
extern void Indirect( char &kwfar. fn() );
.millust end
.discuss begin
declares the function
.mono Indirect
to be near, taking one parameter
.mono fn
which is a pointer
.* which is near
to a far function that returns a
.kw char
..ct ..li .
.discuss end
.keep break
.millust begin
extern int StoreSysTbl( struct systbl * &kwfar. sysptr );
.millust end
.discuss begin
is an invalid declaration, since it attempts to declare
.mono sysptr
to be far.
All parameters must be near, since
they reside in the normal data area that is always near.
.discuss end
.keep end
.*
.section The &kwnear_sp. Keyword for &wc386.
.*
.pp
The
.kwix &kwnear_sp.
.kwfont &kwnear.
keyword is a type qualifier that modifies the token that follows it.
If
.kwix &kwnear_sp.
.kwfont &kwnear.
precedes
.mono *
(as in
.mono &kwnear. *
..ct ), then the pointer points to something that is near (in the
normal data region).
Otherwise, if
.kwix &kwnear_sp.
.kwfont &kwnear.
precedes the identifier of the object or function being declared (as in
.mono &kwnear. x
..ct ), then the object or function is near.
.pp
The keyword
.kwix &kwnear_sp.
.kwfont &kwnear.
can only be applied to function and object names and the
indirection (pointer) symbol
.mono *
..ct ..li .
.pp
For programmers using the small memory model, the
.kwix &kwnear_sp.
.kwfont &kwnear.
keyword is not required, but may be useful for making
the program more readable.
.* .pp
.* In fact, the
.* .kwix &kwnear_sp.
.* .kwfont &kwnear.
.* keyword has no effect.
.* Since &wc386. only supports one memory model, where all of the
.* program's data is always near (there is no option to make it far),
.* the
.* .kwix &kwnear_sp.
.* .kwfont &kwnear.
.* keyword is most useful for making the program more readable.
.*
..im ptr16
.*
.endlevel

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -