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 17 of 28 Topic 24993 of 28006
Post > Topic >>

Re: Number of bits in C99 float types?

by "christian.bau" <christian.bau@[EMAIL PROTECTED] > Mar 18, 2008 at 11:06 AM

On Mar 17, 10:08 pm, Eric Sosman <Eric.Sos...@[EMAIL PROTECTED]
> wrote:

>      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?

No. On some x86 systems the compiler uses sizeof (long double) = 16,
but the hardware uses only ten bytes. What this particular assignment
of 42.0L does depends on the code that the compiler generated: The
compiler could load the number 42 into an 80 bit floating point
register, and store the content of the register. This will modify 10
bytes and leave ten bytes unchanged. Or the compiler could have 16
byte lying around somewhere and do effectively the same as

  static long double tmp = 42.0L;
  memcpy (u.buff, &tmp, sizeof (tmp));

which will overwrite 16 bytes. Or the compiler could decide that
operations with 32 bit integers are much much faster than floating
point, but 16 bit integers are slower, so it could store 12 byte using
three 32-bit integer instructions. As long as the resulting 16 byte
are a valid representation for the number 42.0L, it is all correct.
 




 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:06:54 CST 2008.