Previous - Up - Next
4.10 Comparison to C/C++
The algorithmic language used to express method bodies in DML is an
extended subset of ISO C, with some C++ extensions such as new
and delete. The DML-specific statements and expressions are
described in Sections 4.11 and 4.12.
DML defines the following additional built-in data types:
- int1, ..., int64, uint1, ...,
uint64
- Signed and unsigned specific-width integer types. Widths from 1 to
64 are allowed.
- bool
- The generic boolean datatype, consisting of the values true
and false. It is is not an integer type, and the only implicit
conversion is to uint1
DML also supports the non-standard C extension
typeof(expr) operator, as provided by some modern C
compilers such as GCC.
Most forms of C statements and expressions can be used in DML, with the
exceptions listed below. Some of these limitations may be removed in a
later version of DML.
- Local variable declarations must use the keyword local or
static, as in
method m() {
static int call_count = 0;
local int n = 0;
local float f;
...
}
(only one variable can be introduced per declaration). Local variables
must be declared at the beginning of a compound statement. Static
variables have the same meaning as in C. For symmetry with C, the keyword
auto may be used as a synonym for local.
- Plain C functions (i.e., not DML methods) can be called using normal
function call syntax, as in "f(x)", but C functions can not be
defined in DML itself; they can either be placed in a C file and be
compiled and linked separately, or be placed in a %footer or
%header section in the DML file. In both cases, the function
must also be declared as extern in the DML source code.
- return statements do not take a return value as argument;
output parameters of methods must be assigned explicitly.
- Type casts must be written as cast(expr,
type).
- Comparison operators and logical operators produce results of type
bool, not integers.
- Conditions in if, for, while, etc. must
be proper booleans; e.g., if (i == 0) is allowed, and if
(b) is allowed if b is a boolean varable, but if
(i) is not, if i is an integer.
- the sizeof operator can only be used on expressions. To
take the size of a datatype, the sizeoftype operator must be
used.
- Comma-expressions are only allowed in the head of
for-statements, as in
for (i = 10, k = 0; i > 0; --i, ++k) ...
- delete and throw can only be used as statements
in DML, not as expressions.
- throw does not take any argument, and catch cannot
switch on the type or value of an exception.
- Type declarations do not allow the use of union.
Previous - Up - Next