Table of Contents Previous Next
Logo
The Slice Language : 4.8 Basic Slice Types
Copyright © 2003-2010 ZeroC, Inc.

4.8 Basic Slice Types

Slice provides a number of built-in basic types, shown in Table 4.1.
Table 4.1. Slice basic types.
false or true
−128−127 or 0−2551
≥ 8 bits
−215 to 215−1
≥ 16 bits
−231 to 231−1
≥ 32 bits
−263 to 263−1
≥ 64 bits
≥ 32 bits
≥ 64 bits
All Unicode characters, excluding
the character with all bits zero.

1
The range depends on whether byte maps to a signed or an unsigned type.

All the basic types (except byte) are subject to changes in representation as they are transmitted between clients and servers. For example, a long value is byte-swapped when sent from a little-endian to a big-endian machine. Similarly, strings undergo translation in representation if they are sent, for example, from an EBCDIC to an ASCII implementation, and the characters of a string may also change in size. (Not all architectures use 8‑bit characters). However, these changes are transparent to the programmer and do exactly what is required.

4.8.1 Integer Types

Slice provides integer types short, int, and long, with 16‑bit, 32‑bit, and 64‑bit ranges, respectively. Note that, on some architectures, any of these types may be mapped to a native type that is wider. Also note that no unsigned types are provided. (This choice was made because unsigned types are difficult to map into languages without native unsigned types, such as Java. In addition, the unsigned integers add little value to a language. See [9] for a good treatment of the topic.)

4.8.2 Floating-Point Types

These types follow the IEEE specification for single- and double-precision floating-point representation [6]. If an implementation cannot support IEEE format floating-point values, the Ice run time converts values into the native floating-point representation (possibly at a loss of precision or even magnitude, depending on the capabilities of the native floating-point format).

4.8.3 Strings

Slice strings use the Unicode character set. The only character that cannot appear inside a string is the zero character.1
The Slice data model does not have the concept of a null string (in the sense of a C++ null pointer). This decision was made because null strings are difficult to map to languages without direct support for this concept (such as Python). Do not design interfaces that depend on a null string to indicate “not there” semantics. If you need the notion of an optional string, use a class (see Section 4.11), a sequence of strings (see Section 4.9.3), or use an empty string to represent the idea of a null string. (Of course, the latter assumes that the empty string is not other­wise used as a legitimate string value by your application.)

4.8.4 Booleans

Boolean values can have only the values false and true. Language mappings use the corresponding native boolean type if one is available.

4.8.5 Bytes

The Slice type byte is an (at least) 8‑bit type that is guaranteed not to undergo any changes in representation as it is transmitted between address spaces. This guar­antee permits exchange of binary data such that it is not tampered with in transit. All other Slice types are subject to changes in representation during transmission.

1
This decision was made as a concession to C++, with which it becomes impossibly difficult to manipulate strings with embedded zero characters using standard library routines, such as strlen or strcat.


Table of Contents Previous Next
Logo