cppannotations/yo/first/datatypes.yo
Frank B. Brokken 4d48524f9e WIP
git-svn-id: https://cppannotations.svn.sourceforge.net/svnroot/cppannotations/trunk@498 f6dd340e-d3f9-0310-b409-bdd246841980
2010-12-20 14:40:35 +00:00

65 lines
3.9 KiB
Text

In bf(C) the following i(built-in) data types are available: tt(void, char,
short, int, long, float) and tt(double). bf(C++) extends these built-in types
with several additional built-in types: the types ti(bool), ti(wchar_t),
ti(long long) and ti(long double) (Cf. i(ANSI/ISO) draft (1995),
par. 27.6.2.4.1 for examples of these very long types). The type
ti(long long) is merely a double-long tt(long) datatype. The type
ti(long double) is merely a double-long tt(double) datatype. These built-in
types as well as pointer variables are called
emi(primitive types)hi(type: primitive) in the annotations().
There is a subtle issue to be aware of when converting applications developed
for 32-bit architectures to 64-bit architectures. When converting 32-bit
programs to 64-bit programs, only tt(long) types and pointer types change in
size from 32 bits to 64 bits; integers of type tt(int) remain at their size of
32 bits. This may cause data truncation when assigning pointer or tt(long)
types to tt(int) types. Also, problems with sign extension can occur when
assigning expressions using types shorter than the size of an tt(int) to an
tt(unsigned long) or to a pointer. More information about this issue can be
found
url(here)(http://developers.sun.com/solaris/articles/ILP32toLP64Issues.html).
Except for these built-in types the class-type tt(string) is available
for handling character strings. The datatypes tt(bool), and tt(wchar_t) are
covered in the following sections, the datatype tt(string) is covered in
chapter ref(String). Note that recent versions of bf(C) may also have adopted
some of these newer data types (notably tt(bool) and tt(wchar_t)).
Traditionally, however, bf(C) doesn't support them, hence they are mentioned
here.
Now that these new types are introduced, let's refresh your memory about
em(letters) that can be used in emi(literal constants) of various
hi(letters in literal constants) types. They are:
itemization(
it() ti(b) or tt(B): in addition to its use to indicate a hexadecimal
value, it can also be used to define a emi(binary constant). E.g., tt(0b101)
equals the decimal value 5.
it() ti(E) or tt(e): hi(literal floating point value using E) the
emi(exponentiation) character in floating point literal values. For example:
tt(1.23E+3). Here, tt(E) should be pronounced (and interpreted) as: em(times 10
to the power). Therefore, tt(1.23E+3) represents the value tt(1230).
it() ti(F) hi(literal float using F) can be used as em(postfix) to a
non-integral numeric constant to indicate a value of type tt(float), rather
than tt(double), which is the default. For example: tt(12.F) (the dot
transforms 12 into a floating point value); tt(1.23E+3F) (see the previous
example. tt(1.23E+3) is a tt(double) value, whereas tt(1.23E+3F) is a
tt(float) value).
it() ti(L) hi(literal wchar_t string L) can be used as em(prefix) to
indicate a character string whose elements are tt(wchar_t)-type
characters. For example: tt(L"hello world").
it() tt(L) hi(literal long int using L) can be used as em(postfix) to an
integral value to indicate a value of type tt(long), rather than tt(int),
which is the default. Note that there is no letter indicating a tt(short)
type. For that a tt(static_cast<short>()) must be used.
it() ti(p), to specify the power hi(power specification using p) in
hexadecimal floating point numbers. E.g. tt(0x10p4). The exponent itself is
read as a decimal constant and can therefore not start with 0x. The exponent
part is interpreted as a power of 2. So tt(0x10p2) is (decimal) equal to 64:
tt(16 * 2^2).
it() ti(U) hi(literal unsigned using U) can be used as em(postfix) to an
integral value to indicate an tt(unsigned) value, rather than an tt(int).
It may also be combined with the postfix tt(L) to produce an tt(unsigned long
int) value.
)
And, of course: the tt(x) and tt(a) until tt(f) characters can be used to
specify hexadecimal constants (optionally using capital letters).