help-gplusplus
[Top][All Lists]
Advanced

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

Re: Bus error after casting (well defined) const unsigned char * to cons


From: Martin Kaul
Subject: Re: Bus error after casting (well defined) const unsigned char * to const double *
Date: Fri, 11 Aug 2006 17:03:05 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.10) Gecko/20050716 Thunderbird/1.0.6 Mnenhy/0.7.2.0

Earl Purple wrote:
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.
hmm try to define the const double * as volatile

        volatile const double *d_ptr = ...;

Volatile variables not optimised by the compiler...

regards
  Martin


reply via email to

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