Skip to content
RED SAGSkills
hard20 pts · first answer countsembedded-cundefined-behaviour

Reading a float as uint32_t

This code reads the bits of a float. Why can it give wrong results at -O2, and what is the safe way?

float f = read_sensor();
uint32_t bits = *(uint32_t *)&f;
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions