[GRASS5] Endian tests

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)];

??

Hamish

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@gclements.plus.com>