You have:
struct pts_t { uint32_t lsb; uint32_t msb; };
It:
pts_t t; double timestamp = t;
completely "safe", in the sense that it will not compile, so it cannot harm. You have not defined type pts_t ; you defined type struct pts_t .
It:
struct pts_t t; double timestamp = t;
also will not compile, because you cannot convert (either explicitly, cast, or implicitly with an assignment) a value of type struct for an object with a numeric type.
I humbly suggest that you save some time if you tried this before publication.
Probably the easiest approach is to use memcpy() :
#include <assert.h> #include <string.h> /* ... */ struct pts_t t = { some_lsb_value, some_msbZ_value }; double timestamp; assert(sizeof t == sizeof timestamp); memcpy(×tamp, &t, sizeof timestamp);
By using memcpy() rather than casting pointers, you avoid the risk of improper memory access; depending on the system, your structure may require more or less strict alignment than double .
There is also no guarantee that your structure is the same size as double . The structure is almost certainly 64 bits, and double is probably 64 bits, but none of them are guaranteed, and it does not interfere with making your assumptions explicit.
This leaves open the question of whether the values ββthat you saved in t.lsb and t.msb , taken together, represent a valid double value, especially for the desired value. The language says very little about how floating point types are represented. In particular, consensus can and does depend on different systems. It is up to you to make sure that reinterpreting the view in this way makes sense - and your code is most likely not portable.