开发者

GCC 4.0.2 dereference pointer to double type member of structure raises SIGBUS error

开发者 https://www.devze.com 2023-03-22 05:17 出处:网络
The follow sample code looks OK to me but always fails executing on Solaris with SIGBUS error if compiled with GCC 4.0.2, however it runs fine if compiled with GC开发者_StackOverflow社区C 3.4.2 versio

The follow sample code looks OK to me but always fails executing on Solaris with SIGBUS error if compiled with GCC 4.0.2, however it runs fine if compiled with GC开发者_StackOverflow社区C 3.4.2 version. Any thought?

        //params is a pointer to a structure Param, which has a member d whose type is double. It was initiated/allocated through JNI.

        params->d = 5.0;
        double *b = &params->d;
        double c = params->d;
        c += *b;

SIGBUS was raised at the last line, i.e. dereferencing the pointer and accessing the content is causing the problem.

Thanks, Charles


That sounds like an alignment issue to me. IIRC, double has to be aligned to 64 bit.

0

精彩评论

暂无评论...
验证码 换一张
取 消