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

📄 cpwcc.gml

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 GML
📖 第 1 页 / 共 5 页
字号:
prototypes.
This keyword can be used under 32-bit OS/2 to call 16-bit functions
from your 32-bit flat model program.
Integer arguments will automatically be converted to 16-bit integers,
and 32-bit pointers will be converted to far16 pointers before
calling a special thunking layer to transfer control to the 16-bit
function.
.np
&product predefines the macros
.kwm _far16
and
.kwm _Far16
to be equivalent to the
.kwm __far16
keyword.
This keyword is compatible with Microsoft C.
.np
In the OS/2 operating system (version 2.0 or higher), the first 512
megabytes of the 4 gigabyte segment referenced by the DS register is
divided into 8192 areas of 64K bytes each.
A far16 pointer consists of a 16-bit selector referring to one of the
64K byte areas, and a 16-bit offset into that area.
.np
A pointer declared as,
.illust begin
[type] __far16 *name;
.illust end
.pc
defines an object that is a far16 pointer.
If such a pointer is accessed in the 32-bit environment, the compiler
will generate the necessary code to convert between the far16
pointer and a "flat" 32-bit pointer.
.np
For example, the declaration,
.millust begin
char __far16 *bufptr;
.millust end
.pc
declares the object
.id bufptr
to be a far16 pointer to
.kw char.
.np
A function declared as,
.illust begin
[type] __far16 func( [arg_list] );
.illust end
.pc
declares a 16-bit function.
Any calls to such a function from the 32-bit environment will cause
the compiler to convert any 32-bit pointer arguments to far16
pointers, and any
.kw int
arguments from 32 bits to 16 bits.
(In the 16-bit environment, an object of type
.kw int
is only 16 bits.)
Any return value from the function will have its return value
converted in an appropriate manner.
.np
For example, the declaration,
.code begin
char * __far16 Scan( char *buffer, int len, short err );
.code end
.pc
declares the 16-bit function
.id Scan.
When this function is called from the 32-bit environment, the
.id buffer
argument will be converted from a flat 32-bit pointer to a far16
pointer (which, in the 16-bit environment, would be declared as
.mono char __far *.
The
.id len
argument will be converted from a 32-bit integer to a 16-bit integer.
The
.id err
argument will be passed unchanged.
Upon returning, the far16 pointer (far pointer in the 16-bit
environment) will be converted to a 32-bit pointer which describes the
equivalent location in the 32-bit address space.
.*
.note _Seg16 &optdag.
.ix 'keywords' '_Seg16'
(32-bit only)
&product recognizes the
.kwm _Seg16
keyword which has a similar but not identical function as the
.kwm __far16
keyword described above.
This keyword is compatible with IBM C Set/2 and IBM VisualAge C++.
.np
In the OS/2 operating system (version 2.0 or higher), the first 512
megabytes of the 4 gigabyte segment referenced by the DS register is
divided into 8192 areas of 64K bytes each.
A far16 pointer consists of a 16-bit selector referring to one of the
64K byte areas, and a 16-bit offset into that area.
.np
Note that
.kwm _Seg16
is
.bd not
interchangeable with
.kwm __far16.
.np
A pointer declared as,
.illust begin
[type] * _Seg16 name;
.illust end
.pc
defines an object that is a far16 pointer.
Note that the
.kwm _Seg16
appears on the right side of the
.mono *
which is opposite to the
.kwm __far16
keyword described above.
.np
For example,
.millust begin
char * _Seg16 bufptr;
.millust end
.pc
declares the object
.id bufptr
to be a far16 pointer to
.kw char
(the same as above).
.np
The
.kwm _Seg16
keyword may not be used to describe a 16-bit function.
A
.kw #pragma
directive must be used instead.
A function declared as,
.illust begin
[type] * _Seg16 func( [parm_list] );
.illust end
.pc
declares a 32-bit function that returns a far16 pointer.
.np
For example, the declaration,
.code begin
char * _Seg16 Scan( char * buffer, int len, short err );
.code end
.pc
declares the 32-bit function
.mono Scan.
No conversion of the argument list will take place.
The return value is a far16 pointer.
.*
.note __pragma
.ix 'keywords' '__pragma'
&cmppname supports the
.kwm __pragma
keyword to support in-lining of member functions.
The
.kwm __pragma
keyword must be followed by parentheses containing a string that names
an auxiliary pragma.
Here is a simplified example showing usage and syntax.
.exam begin
#pragma aux fast_mul = \
    "imul eax,edx" \
    parm caller [eax] [edx] \
    value struct;

struct fixed {
    unsigned v;
};

fixed __pragma( "fast_mul") operator *( fixed, fixed );

fixed two = { 2 };
fixed three = { 3 };

fixed foo()
{
    return two * three;
}
.exam end
.np
See the chapters entitled :HDREF refid='prg86'. and
:HDREF refid='prg386'. for more information on pragmas.
.*
.note __int64
.ix 'keywords' '__int64'
&product supports the
.kwm __int64
keyword to define 64-bit integer data objects.
.exam begin
static __int64 bigInt;
.exam end
.np
Also supported are signed and unsigned 64-bit integer constants.
.begnote
.note signed __int64
Use the "i64" suffix for a signed 64-bit integer constant.
.exam begin
12345i64
12345I64
.exam end
.note unsigned __int64
Use the "ui64" suffix for an unsigned 64-bit integer constant.
.exam begin
12345Ui64
12345uI64
.exam end
.endnote
.np
The run-time library supports formatting of
.kwm __int64
items (see the description of the
.kwm printf
library function).
.exam begin
#include <stdio.h>
#include <limits.h>

void main()
{
    __int64 bigint;
    __int64 bigint2;

    bigint2 = 8I64 * (LONG_MAX + 1I64);
    for( bigint = 0;
         bigint <= bigint2;
         bigint += bigint2 / 16 ) {
        printf( "Hello world %Ld\n", bigint );
    }
}
.exam end
.begnote Restrictions
.note switch
An
.kwm __int64
expression cannot be used in a
.us switch
statement.
.note bit fields
More than 32 bits in a 64-bit bitfield is not supported.
.endnote
.*
.endnote
.*
.section *refid=wccbase Based Pointers
.*
.np
.ix 'based pointers'
Near pointers are generally the most efficient type of pointer because
they are small, and the compiler can assume knowledge about what
segment of the computer's memory the pointer (offset) refers to.
Far pointers are the most flexible because they allow the programmer
to access any part of the computer's memory, without limitation to a
particular segment.
However, far pointers are bigger and slower because of the additional
flexibility.
.np
Based pointers are a compromise between the efficiency of near
pointers and the flexibility of far pointers.
With based pointers, the programmer takes responsibility to tell the
compiler which segment a near pointer (offset) belongs to, but may
still access segments of the computer's memory outside of the normal
data segment (DGROUP).
The result is a pointer type which is as small as and almost as
efficient as a near pointer, but with most of the flexibility of a far
pointer.
.np
An object declared as a based pointer falls into one of the following
categories:
.begbull $compact
.* .bull
.* the based pointer is in the same segment as another named object,
.bull
the based pointer is in the segment described by another object,
.bull
the based pointer, used as a pointer to another object of the same
type (as in a linked list), refers to the same segment,
.bull
the based pointer is an offset to no particular segment, and must be
combined explicitly with a segment value to produce a valid pointer.
.endbull
.np
To support based pointers, the following keywords are provided:
.ix '__based'
.ix '__segment'
.ix '__segname'
.ix '__self'
.millust begin
__based
__segment
__segname
__self
.millust end
.np
The following operator is also provided:
.millust begin
:>
.millust end
.np
These keywords and operator are described in the following sections.
.np
Two macros, defined in
.fi malloc.h,
are also provided:
.ix '_NULLSEG'
.ix '_NULLOFF'
.millust begin
_NULLSEG
_NULLOFF
.millust end
.pc
They are used in a manner similar to
.kwm NULL,
but are used with objects declared as
.kwm __segment
and
.kwm __based
respectively.
.*
.beglevel
.*
.section Segment Constant Based Pointers and Objects
.*
.np
.ix 'based pointers' 'segment constant'
A segment constant based pointer or object has its segment value based
on a specific, named segment.
A segment constant based object is specified as:
.illust begin
[type] __based( __segname( "segment" ) ) object_name;
.illust end
.pc
and a segment constant based pointer is specified as:
.illust begin
[type] __based( __segname( "segment" ) ) *object-name;
.illust end
.pc
where
.id segment
is the name of the segment in which the pointer or object is based.
As shown above, the segment name is always specified as a string.
There are three special segment names recognized by the compiler:
.millust begin
"_CODE"
"_CONST"
"_DATA"
.millust end
.pc
The
.mono "_CODE"
segment is the default code segment.
The
.mono "_CONST"
segment is the segment containing constant values.
The
.mono "_DATA"
segment is the default data segment.
If the segment name is not one of the three recognized names, then a
segment will be created with that name.
If a segment constant based object is being defined, then it will be
placed in the named segment.
If a segment constant based pointer is being defined, then it can
point at objects in the named segment.
.np
The following examples illustrate segment constant based pointers and
objects.
.exam begin
int __based( __segname( "_CODE" ) )  ival = 3;
int __based( __segname( "_CODE" ) ) *iptr;
.exam end
.pc
.id ival
is an object that resides in the default code segment.
.id iptr
is an object that resides in the data segment (the usual place for
data objects), but points at an integer which resides in the default
code segment.
.id iptr
is suitable for pointing at
.id ival.
.exam begin
char __based( __segname( "GOODTHINGS" ) ) thing;
.exam end
.pc
.id thing
is an object which resides in the segment
.id GOODTHINGS,
which will be created if it does not already exist.
(The creation of segments is done by the linker, and is a method
of grouping objects and functions.
Nothing is implicitly created during the execution of the program.)
.*
.section Segment Object Based Pointers
.*
.np
.ix 'based pointers' 'segment object'
A segment object based pointer derives its segment value from another
named object.
A segment object based pointer is specified as follows:
.illust begin
[type] __based( segment ) *name;
.illust end
.pc
where
.id segment
is an object defined as type
.kwm __segment.
.np
An object of type
.kwm __segment
may contain a segment value.
Such an object is particularly designed for use with segment object
based pointers.
.np
The following example illustrates a segment object based pointer:
.exam begin
__segment            seg;
char __based( seg ) *cptr;
.exam end
.pc
The object
.id seg
contains only a segment value.
Whenever the object
.id cptr
is used to point to a character, the actual pointer value will be made
up of the segment value found in
.mono seg
and the offset value found in
.id cptr.
The object
.id seg
might be assigned values such as the following:
.begbull $compact
.bull
a constant value (e.g., the segment containing screen memory),
.bull
the result of the library function
.kw _bheapseg,
.bull
the segment por

⌨️ 快捷键说明

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