397
APPENDIX D Notes on Using Little Endian Areas
#define STRMOVE(DEST,SRC) DEST.c=SRC.c;DEST.i=SRC.i;
void main(void) {
STRMOVE(little_st,normal_st);
}
Moreover, as the member allocation for a structure is different for ea ch compiler, it may differ
from that of another compiler. In this a case, the correct result cannot be acquired.
When the member allocations for structures differ, d o not allocate the corres ponding structure
variables to a little endian area.
■Manipulating Data Other Than Character Arrays with a Character String Manipulation Function
Character string manipulation functions provided by standar d libraries perform processing in
byte-units. Therefore, the character string manipulation function does not produce the correct
results for variables of types other than char, unsigned char, and signed char, which are
allocated to little endian areas. Do not perform such oper ations.
[Example of incorrect processing] Transfer of word data by memcpy
int big = 0x01020304; /* Big endian area */
extern int little; /* Little endian area */
memcpy(&little,&big,4); /* Transfer by memcpy */
The result of the above transfer is rendered incorrect by word d ata transfer as follows:
■Specifying the Option -K Lib when Using a Character String Manipulation Function
When the -K lib option is specified, the compiler performs inline expansion for var ious characte r
string manipulation functions. In this case, these f unctions may empl oy proces sing in half-word
or word units to optimize processing. Therefore, the processing for little endi an areas is
executed incorrectly.
When processing a little endian area using a character string ma nipulation function, do not
specify the option -K lib. Also, do not specify the option -04 and -K speed, which include the
option -K lib.
■Using the Types Double and Long Double
When variables of the types double and long dou ble are accessed, the up per and lower word
are accessed, respectively. Therefore, if double and long double type variables allocated to
little endian areas are accessed, the correct result cannot be acquired.
Variables of the same type allocated to little en dian a reas can be assi gned to ea ch other . As a
result of optimization, however, these assigned variables ma y be replaced with constants.
01 02 03 04 01 02 03 04(Big endian area) (Little endian area)(Correct result)memcpy01020304