I want to compile a single precision float into flash as 0xFFFFFFFF
(unitialized flash).
When I try (FLOAT32) ((UINT32) 0xFFFFFFFF)
, it converts to a floating point (0x0000804F)
during the compilation process instead of 0xFFFFFFFF
.
This applies to the initialization of a field in a struct in file scope. When I think of it, this means that the compiler is expecting a FLOAT32 literal.
I am beginning to wonder whether this is actually possible.
[EDIT: This applies to initialization of a field in a struct in file scope]
In C, the best way is to use a
union
. Store into theUINT32
field, then read it out from thefloat
field.Complete discussion here: How to convert or cast a float into its bit sequence such as a long
Also, if you have C99 features available, you can use designated initializers to specify which of the union fields you want to assign. Even if you don't have C99 you can just make sure that the
UINT32
fields in theunion
is the first one, so it will be assigned by default. http://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html