The best method would be to use an ASCII text file:
0.0
3.1416
3.90798504668055
in that it would be portable and work with any kind of floating point implementation to a degree.
Reading raw binary data from a double
's memory address is not portable at all, and is bound to fail in some different implementation.
You may of course use a binary format for compactness, but a portable C function writing in that format would not look like your snippet at all.
At the very least, the code should be surrounded by a series of ifs/ifdefs checking that the memory representation of double
s used by the current machine exactly matches the one expected by the Python interpreter.
Writing such code would be difficult, which is why I'm suggesting the easy, clean, portable and human-readable solution of ASCII text.
This would be my definition of "best".