Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: Number of b...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 13 of 28 Topic 24993 of 28006
Post > Topic >>

Re: Number of bits in C99 float types?

by Keith Thompson <kst-u@[EMAIL PROTECTED] > Mar 18, 2008 at 09:48 AM

jacob navia <jacob@[EMAIL PROTECTED]
> writes:
> Eric Sosman wrote:
>> jacob navia wrote:
>>> Eric Sosman wrote:
[...]
>>>>     If sizeof(long double) * CHAR_BIT == 96 on some system,
>>>> then 96 *is* the number of bits in a long double, not some
>>>> kind of "rounded up" result.  
>>>
>>> No. In the x86 the long double is 10 bytes, but it
>>> is rounded up into 12 (lcc-win) or even 16, just for
>>> alignment reasons.
>>
>>     So, I can safely store a few additional chars in the
>> extra bytes?
>>
>>     union {
>>         long double aligner;
>>         unsigned char buff[16];
>>     } u;
>>     memset (u.buff, 'x', sizeof u.buff);
>>     *(long double*)u.buff = 42.0L;
>>     assert (u.buff[10] == 'x');
>>
>> All happy and hunky-dory, right?
>>
>
> ??? What do you want to prove?
>
> That long doubles are NOT 10 bytes?
>
> Or what?
>
> I do not see the point.

If sizeof(long double) == 12, then long double is 12 bytes, not 10
bytes.  It might be the case that only 10 of those bytes contribute to
the value, and the other two bytes are some sort of padding added by
the compiler.  A long double isn't 10 bytes plus some padding that
isn't part of the long double; it's 12 bytes *including* two bytes of
padding.

Similarly, if this structure:
    struct {
        int i;  /* assume 4 bytes */
        char c; /* 1 byte */
    };
is padded to 8 bytes, then the size of the structure really is 8
bytes; the 3 bytes of padding are part of the structure.

You're making a valid point: that a C long double is based on a
10-byte hardware floating-point format.  But that 10-byte format is
not a C long double; the padded 12-byte data type is a C long double.

-- 
Keith Thompson (The_Other_Keith) <kst-u@[EMAIL PROTECTED]
>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
 




 28 Posts in Topic:
Number of bits in C99 float types?
Dom Fulton <wes104@[EM  2008-03-17 20:13:21 
Re: Number of bits in C99 float types?
Harald van =?UTF-8?b?RMSz  2008-03-17 21:16:44 
Re: Number of bits in C99 float types?
Dom Fulton <wes104@[EM  2008-03-17 20:49:51 
Re: Number of bits in C99 float types?
jacob navia <jacob@[EM  2008-03-17 21:56:45 
Re: Number of bits in C99 float types?
Eric Sosman <Eric.Sosm  2008-03-17 17:12:21 
Re: Number of bits in C99 float types?
jacob navia <jacob@[EM  2008-03-17 22:29:08 
Re: Number of bits in C99 float types?
santosh <santosh.k83@[  2008-03-18 03:19:38 
Re: Number of bits in C99 float types?
Eric Sosman <Eric.Sosm  2008-03-17 18:08:16 
Re: Number of bits in C99 float types?
Dom Fulton <wes104@[EM  2008-03-17 23:13:49 
Re: Number of bits in C99 float types?
jacob navia <jacob@[EM  2008-03-18 00:20:15 
Re: Number of bits in C99 float types?
santosh <santosh.k83@[  2008-03-18 04:58:16 
Re: Number of bits in C99 float types?
jacob navia <jacob@[EM  2008-03-18 00:32:24 
Re: Number of bits in C99 float types?
Keith Thompson <kst-u@  2008-03-18 09:48:42 
Re: Number of bits in C99 float types?
ymuntyan@[EMAIL PROTECTED  2008-03-17 18:16:56 
Re: Number of bits in C99 float types?
user923005 <dcorbit@[E  2008-03-17 18:41:40 
Re: Number of bits in C99 float types?
ymuntyan@[EMAIL PROTECTED  2008-03-17 20:59:40 
Re: Number of bits in C99 float types?
"christian.bau"  2008-03-18 11:06:52 
Re: Number of bits in C99 float types?
Ian Collins <ian-news@  2008-03-18 09:17:21 
Re: Number of bits in C99 float types?
Harald van =?UTF-8?b?RMSz  2008-03-17 22:06:40 
Re: Number of bits in C99 float types?
Harald van =?UTF-8?b?RMSz  2008-03-17 22:09:38 
Re: Number of bits in C99 float types?
Keith Thompson <kst-u@  2008-03-18 09:40:17 
Re: Number of bits in C99 float types?
Dom Fulton <wes104@[EM  2008-03-18 10:50:49 
Re: Number of bits in C99 float types?
santosh <santosh.k83@[  2008-03-18 18:06:22 
Re: Number of bits in C99 float types?
Eric Sosman <esosman@[  2008-03-18 09:33:49 
Re: Number of bits in C99 float types?
Ben Bacarisse <ben.use  2008-03-18 11:48:16 
Re: Number of bits in C99 float types?
Harald van =?UTF-8?b?RMSz  2008-03-18 18:33:38 
Re: Number of bits in C99 float types?
santosh <santosh.k83@[  2008-03-19 00:36:37 
Re: Number of bits in C99 float types?
Keith Thompson <kst-u@  2008-03-18 23:34:32 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 12:12:42 CST 2008.