📄 constant.gml
字号:
.ix 'constant'
.pp
A constant is a value which is fixed at compilation time and is
often just a number, character or string.
Every constant has a type
which is determined by its form and value.
For example, the value
.mono 1
may have the type
.kw signed int
..ct ,
while the value
.mono 400000
may have the type
.kw signed long
..ct ..li .
In many cases, the type of the constant does not matter.
If, for
example, the value
.mono 1
is assigned to an object of type
.kw long int
..ct ,
then the value
.mono 1
will be converted to a
long integer before the assignment takes place.
.*
.section Integer Constants
.*
.ix 'constant' 'integer'
.ix 'integer' 'constant'
.pp
An integer constant begins with a digit and contains no fractional
or exponent part. A prefix may be included which defines whether
the constant is in octal, decimal or hexadecimal format.
.pp
A constant
may be suffixed by
.mono u
or
.mono U
indicating an
.kw unsigned int
..ct , or by
.mono l
or
.mono L
indicating a
.kw long int
..ct , or by both indicating an
.kw unsigned long int
..ct ..li .
.pp
If a constant does not start with a zero and contains a sequence of
digits, then it is interpreted as a decimal (base 10) constant.
These are decimal constants:
.millust begin
7
762
98765L
.millust end
.pp
If the constant starts with
.mono 0x
or
.mono 0X
followed
by the digits from
.mono 0
through
.mono 9
and the letters
.mono a
(or
.mono A
..ct ) through
.mono f
(or
.mono F
..ct ), then the constant is interpreted as a hexadecimal (base 16)
constant.
The letters
.mono A
through
.mono F
represent the values
10 through 15 respectively.
These are hexadecimal constants:
.millust begin
0X07FFF
0x12345678L
0xFABE
.millust end
.keep begin
.pp
If a constant starts with a zero, then it is an octal constant
and may contain only the digits 0 through 7.
These are octal constants:
.millust begin
017
0735643L
0
.millust end
.keep end
.pc
Note that the constant
.mono 0
is actually
an octal constant, but is zero in decimal, octal and hexadecimal.
.pp
The following table describes what type the compiler will give to a
constant. The left column indicates what
base (decimal, octal or hexadecimal) is used
and what suffixes (
..ct .mono U
or
.mono L
..ct )
are present.
The right column indicates the types that may be given to such a
constant.
The type of an integer constant is the first type from the table
in which its value can be accurately represented.
..sk 1 c
.if &e'&nobox eq 0 .do begin
.boxdef
..if '&format' eq '7x9' ..th ..do begin
.boxcol 15
.boxcol 32
..do end
..el ..do begin
.boxcol 17
.boxcol 38
..do end
.* .cp 15
.boxbeg
汣onstant 汿ype
.boxline
.monoon
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -