Converting long doubles with endianness

Hello,

So I'm attempting to convert the endianness of long doubles, but I'm running into a problem with portability to other machines. I've got a solaris/sparc where long doubles are 16 bytes and an intel/linux where they are 12 bytes.

Anyone got any suggestions or ever had to do this before?

Any help/references would be very appreciated.

jpeg
Last edited on
I was bored, so I decided to solve it:
1
2
3
4
5
6
7
8
9
10
template <typename T>
T invert(T val){
	size_t size=sizeof(T);
	T res=0;
	char *src=((char *)&val)+size-1,
		*dst=(char *)&res;
	for (size_t a=size;a;a--)
		*dst++=*src--;
	return res;
}


EDIT: I don't think I can get it any shorter and faster.
Last edited on
Topic archived. No new replies allowed.