Integers (j.3.5), Integers (f.3.5 of ansi c standard) – Echelon Neuron C User Manual
Page 253

Neuron C Programmer’s Guide
241
Q: What are the number of bits in a character in the execution character set?
What is the size of a wide character—that is, the type of
wchar_t
? (Sec. 2.2.4.2.1)
A:
The execution character set uses an 8-bit representation. The Neuron C
compiler does not support wide characters, but the type of a wide character,
wchar_t, is defined to be unsigned long. (Note that Neuron C defines unsigned
long as 16 bits.)
Integers (J.3.5)
Q: What is the result of converting an integer to a shorter signed integer? What
is the result of converting an unsigned integer to a signed integer of equal length,
if the signed integer cannot represent the unsigned integer’s value? (Sec. 6.3.1.3)
A:
Conversion from long to short may result in data loss, depending on the value
being converted, since this conversion is performed by discarding the most
significant byte of the long integer. If, for example, a long integer containing the
value 513 (hex 0201) was converted to a signed short, discarding the most
significant byte of the long integer would result in the value 1.
Conversion from an unsigned integer to a signed integer of equal length may
result in a negative number. For example, an unsigned short integer may have
the value 255 (hex FF), but when converted to a signed short integer, it is then
interpreted using two’s complement, and the value
becomes -1.
The Neuron C compiler produces diagnostic messages when data might be lost as
the result of an
implicit
conversion operation.
Explicit
conversion, such as
through a cast operation, does not produce a diagnostic message. As an example,
in the code fragment below, the assignment to x results in a diagnostic
warning
message, but the assignment to y does not.
int x, y;
x = 285;
// Data is lost, x is assigned 29.
// Warning is produced.
y = (int)285;
// Data is lost, y is assigned 29.
// No warning
is produced.
Q: What are the results of bitwise operations on signed integers? (Sec. 6.5)
A:
Bitwise operations on signed integers are performed as if the values of the
operands were unsigned. The result is interpreted as signed. Thus, the result of
(-2)|1 is -1.
Integers (F.3.5 of ANSI C Standard)
Q: What are the representations and sets of values of the various types of
integers? What is the order of bits in a multi-unit integer representation? What
is the method of encoding an unsigned integer? What is the method of encoding a
signed integer? (Sec. 3.1.2.5)
A:
An int implies a short int by default, which is 8 bits in Neuron C. The 8-bit
byte is the fundamental unit of storage on the Neuron Chip. A long int is a 16-
bit, or 2-byte, integer representation. The
definitions of the various integer-type ranges. These values are: