help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bus error after casting (well defined) const unsigned char * to const do


From: Earl Purple
Subject: Bus error after casting (well defined) const unsigned char * to const double *
Date: 11 Aug 2006 03:09:13 -0700
User-agent: G2/0.2

g++ 3.4.2 (32 bit) on Solaris:

I am passing doubles in binary format.

So I receive the binary representation for a double (500000 in this
particular case, which is 0x41 0x1e 0x84 0x80 0x00 0x00 0x00 0x00)

If I reinterpret_cast the pointer to const double * then dereference it
I get a Bus Error (core dumped).

The workaround (that works) is to copy the buffer into a double, i.e.
take a double, reinterpret_cast its address to unsigned char * and copy
the buffer. That works, no crash.

It worked fine until I compiled in release mode with O3 optimisation
setting. -ffloat-store flag makes no difference.

The downside of the workaround is it means one more buffer copy. Still
I will use this for now. Is this a known bug (as far as I'm aware it is
not undefined behaviour)? Is it fixed in later versions (but I don't
have a later version).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]