foralex / picoc

Automatically exported from code.google.com/p/picoc
0 stars 0 forks source link

Define variables so script can know if CPU is big or little endian [Feature] #106

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This can be important if your script will run on different CPU's.
The compiler can calculate for you, like this:

static const int __ENDIAN_CHECK__ = 1;

static int Big_Endian = 0;
static int Little_Endian = 0;

#define IsBigEndian       ((*(char*)&__ENDIAN_CHECK__) == 0)
#define IsLittleEndian    ((*(char*)&__ENDIAN_CHECK__) == 1)

void Init()
{
    Big_Endian = IsBigEndian;
    Little_Endian = IsLittleEndian;

    VariableDefinePlatformVar(NULL, "BIG_ENDIAN", &IntType, (union AnyValue *)&Big_Endian, FALSE);
    VariableDefinePlatformVar(NULL, "LITTLE_ENDIAN", &IntType, (union AnyValue *)&Little_Endian, FALSE);
}

Original issue reported on code.google.com by duncan.f...@gmail.com on 1 Aug 2010 at 3:30

GoogleCodeExporter commented 9 years ago
Redefined as "enhancement".

Original comment by zik.sale...@gmail.com on 8 Aug 2010 at 11:43

GoogleCodeExporter commented 9 years ago
Nice idea. Implemented in r533.

Original comment by zik.sale...@gmail.com on 15 Feb 2011 at 4:48