This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: struct ldieee should be packed
- From: Craig Howland <howland at LGSInnovations dot com>
- To: <newlib at sourceware dot org>
- Date: Mon, 1 Feb 2016 11:46:42 -0500
- Subject: Re: struct ldieee should be packed
- Authentication-results: sourceware.org; auth=none
- References: <3CC3E1D9CBEF20449C581E91DFCFAF5B02489E1C at BPXM12GP dot gisp dot nec dot co dot jp>
On 01/30/2016 01:56 AM, Shoichi Sakon wrote:
Hello,
The following test program prints 1.0 instead of -1.0.
-------------------------------------
#include <stdio.h>
int main() {
double x = -1.0;
printf("%f\n",x);
return 0;
}
-------------------------------------
I believe the cause of the problem is the struct ldieee
defined in newlib/libc/stdio/vfieeefp.h is not "packed",
and in the function cvt in newlib/libc/stdio/vfieeefp.h
ld.ieee.sign does not get the proper sign.
When I change all the definitions of
struct ldieee
to
struct __attribute__ ((__packed__)) ldieee
I can get the right result at the test program.
What compiler version and platform are you targeting?
Can you try the following as an experiment? instead of adding packed (which is
non-standard), merge the bitfields to be under a single element instead of
separate ones for you entry of interest. For example, change
#if LDBL_MANT_DIG == 24
struct ldieee
{
unsigned manh:23;
unsigned exp:8;
unsigned sign:1;
};
to
{
unsigned manh:23,
exp:8,
sign:1;
};
Craig