Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #126340

Re: Aligned Issue when malloc()

Path csiph.com!aioe.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Aligned Issue when malloc()
Date Tue, 06 Feb 2018 11:34:39 -0800
Organization None to speak of
Lines 36
Message-ID <lnlgg529ps.fsf@kst-u.example.com> (permalink)
References <7d04ef8a-4410-4855-a69a-34c350465879@googlegroups.com> <874lmumj2n.fsf@bsb.me.uk> <dbe46486-cc00-4ecd-9288-7ef6b54846c9@googlegroups.com> <oqieC.14584$RQ3.6328@fx02.iad> <3c97f1c7-9830-b7b2-9400-6551596eaa81@verizon.net> <3c435029-fc0c-4753-ab8e-8e81342ea09e@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info reader02.eternal-september.org; posting-host="9bf0f7c9b2913a6f5e088f82eff19e7d"; logging-data="10564"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OVNnRhkGWvdYFZi1/IIGG"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock sha1:Z6FF0X0H0o3bU8spa2HRxvhUDnE= sha1:0JYvL1t/KT9+N4qhWxY3EhEN0NE=
Xref csiph.com comp.lang.c:126340

Show key headers only | View raw


supercat@casperkitty.com writes:
> On Tuesday, February 6, 2018 at 8:59:40 AM UTC-6, James R. Kuyper wrote:
>> On 02/06/2018 08:52 AM, Richard Damon wrote:
>> ...
>> > I suspect this is old code, and predates newer standards, because today
>> > you would need to add long double which might have larger requirements
>> > than double, ...
>> 
>> Many people incorrectly think that long double was added in C99. I 
>> couldn't be sure from your wording whether you shared that 
>> misconception. In fact, it has been a standard C type for as long as 
>> there has been a C standard.
>
> So far as I can tell, the "long double" type was traditionally either a
> synonym for "double", or else an IEEE 80-bit extended type; while there
> may have been some platforms in 1989 that would store an 80-bit type
> with 64-bit alignment (and 48 padding bits), I would expect that it was
> far more often stored with 16-bit or 32-bit alignment (using zero or 16
> padding bits).  Note that if a 64-bit platform supports 32-bit loads and
> stores, there may be no advantage to forcing 64-bit alignment since each
> value would require one 64-bit and one 32-bit operation.

To summarize, if you need to define a union with strictest alignment, it
makes sense to include both double and long double members, since it's
at least possible that double could require stricter alignment than long
double.  Even if it's unnecessary, it won't hurt.

As others have mentioned, C11 adds max_align_t in <stddef.h>, making all
this union stuff unnecessary.  Or you can use alignof (_Alignof) to
determine the actual alignment of the type you're using.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Aligned Issue when malloc() hwding <m@amastigote.com> - 2018-02-06 01:17 -0800
  Re: Aligned Issue when malloc() Ian Collins <ian-news@hotmail.com> - 2018-02-06 22:41 +1300
  Re: Aligned Issue when malloc() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-02-06 11:52 +0000
    Re: Aligned Issue when malloc() hwding <m@amastigote.com> - 2018-02-06 04:35 -0800
      Re: Aligned Issue when malloc() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-02-06 13:48 +0000
        Re: Aligned Issue when malloc() "Chris M. Thomasson" <invalid_chris_thomasson@invalid.invalid> - 2018-02-06 12:55 -0800
      Re: Aligned Issue when malloc() Richard Damon <Richard@Damon-Family.org> - 2018-02-06 08:52 -0500
        Re: Aligned Issue when malloc() "James R. Kuyper" <jameskuyper@verizon.net> - 2018-02-06 09:59 -0500
          Re: Aligned Issue when malloc() supercat@casperkitty.com - 2018-02-06 07:20 -0800
            Re: Aligned Issue when malloc() Robert Wessel <robertwessel2@yahoo.com> - 2018-02-06 11:50 -0600
            Re: Aligned Issue when malloc() Keith Thompson <kst-u@mib.org> - 2018-02-06 11:34 -0800
            Re: Aligned Issue when malloc() Egor <egor@ruby.local> - 2018-02-09 16:20 +0200
              Re: Aligned Issue when malloc() supercat@casperkitty.com - 2018-02-15 08:56 -0800
                Re: Aligned Issue when malloc() Egor <egor@ruby.local> - 2018-02-15 19:35 +0200
                Re: Aligned Issue when malloc() supercat@casperkitty.com - 2018-02-15 11:27 -0800
                Re: Aligned Issue when malloc() Egor <egor@ruby.local> - 2018-02-16 02:48 +0200
                Re: Aligned Issue when malloc() supercat@casperkitty.com - 2018-02-16 08:49 -0800
      Re: Aligned Issue when malloc() "James R. Kuyper" <jameskuyper@verizon.net> - 2018-02-06 09:41 -0500

csiph-web