I am writing C for PIC32MX compiled using the Microchip PIC32 C compiler (based on GCC 3.4).
Added . The standard that I follow is GNU99 (C99 with GNU extensions, compiler flag -std=gnu99)
My problem is this: I have some reprogrammable numerical data that is stored either on the EEPROM or in the software flash of the chip. This means that when I want to save a float, I have to execute some type of punning:
typedef union
{
int intval;
float floatval;
} IntFloat;
unsigned int float_as_int(float fval)
{
IntFloat intf;
intf.floatval = fval;
return intf.intval;
}
void StoreInt(unsigned int data, unsigned int address);
void StoreFPVal(float data, unsigned int address)
{
StoreInt(float_as_int(data), address);
}
. ( ) , . float Python, , :
import struct
hex(struct.unpack("I", struct.pack("f", float_value))[0])
... , :
const unsigned int DEFAULTS[] =
{
0x00000001,
0x3C83126F,
}
( X macro, .) , ? , - :
const unsigned int DEFAULTS[] =
{
0x00000001,
COMPILE_TIME_CONVERT(0.005),
}
... , , .
- , ", " , .
- , , , , undefined ( IDB, ).
- , ,
DEFAULTS . , , .