
387
APPENDIX D Notes on Using Little Endian Area
void main(void) {
STRMOVE(little_st,normal_st);
}
Since the structural member placement differs between compilers, the structure may have a
different member placement from a structure compiled by another compiler.
In this case, even the above method cannot produce correct results.
If the member placement of the structure does not match, do not place a structural variable in a
little endian area.
s Specifying the -K Lib Option
The character string operation functions prepared as a standard library does processing in
bytes.
Therefore, correct results cannot be obtained if these functions are used on a little
endian area of a type other than "char," "unsigned char," or "signed."
Avoid the following processing:
Example of problem: Word data transfer using memcpy
int big = 0x01020304;
/* Big endian area
*/
extern int little;
/* Little endian area
*/
memcpy(&little,&big,4); /* Transfer by memcpy */
The above processing ends in the following result that is an error as a word data transfer result.
s Option Specifying the -K Lib Option when Using Character String Operation Functions
If the -K lib option is specified, a compiler applies inline development to several character string
operation functions. For optimum processing, the unit of processing may be changed to half-
word or word.
Therefore, processing cannot be executed correctly on a little endian area.
Do not specify the -K lib option when using character string operation functions for processing
on a little endian area.
Do not use specify the -4 option containing the -K lib option or the -K speed option.
s Using double or long-double Variables
Access to a double or long-double variable is made on the upper or lower word. Therefore,
access to a double or long-double variable in a little endian area does not produce the correct
results.
Although variables of the same type can be assigned to each other in a little endian area,
optimization may substitute these variable assignments with constant assignments.
Do not use double or long-double variables in a little endian area.
memcpy
01
02
03
04
01
02
03
04
01
04
03
02
Big endian area
Little endian area
Correct result