So, I am aware that types from the stdint.h
header provide standardized width integer types, however I am wondering what type or method does one uses to guarantee the size of a double
or other floating point type across platforms? Specifically, this would deal with packing data in a void*
#include <stdio.h>
#include <stdlib.h>
void write_double(void* buf, double num)
{
*(double*)buf = num;
}
double read_double(void* buf)
{
return *(double*)buf;
}
int main(void) {
void* buffer = malloc(sizeof(double));
write_double(buffer, 55);
printf("The double is %f\n", read_double(buffer));
return 0;
}
Say like in the above program, if I wrote that void*
to a file or if it was used on another system, would there be some standard way to guarantee size of a floating point type or double?