[GRASS5] Endian tests

Glynn Clements glynn at gclements.plus.com
Sun Apr 3 23:38:30 EDT 2005


Hamish wrote:

> lib/gis/endian.c uses:
> 
> int G_is_little_endian (void)    
> {
>     union
>     {
>         int testWord;
>         char testByte[4];
>     } endianTest;
>     
>     int swapFlag;
> 
>     endianTest.testWord = 1;
>     
>     if (endianTest.testByte[0] == 1)
>     {
>         swapFlag = 1; /*true: little endian */
>     }
>     else
>     {
>         swapFlag = 0; /* false: big endian */
>     }
>     return swapFlag;
> }
> 
> 
> 
> should that be:
> 
> -        char testByte[4];
> +        char testByte[sizeof(int)];

Probably, although ideally it should be a compile-time test, e.g. 
<endian.h>.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list