Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Alignment problems |
| Date | 2011-12-02 10:27 +1300 |
| Message-ID | <9jq9pfF4d0U42@mid.individual.net> (permalink) |
| References | <jb6gbf$58a$1@speranza.aioe.org> <jb7sfh$221$1@speranza.aioe.org> <jb8ojo$ajt$1@speranza.aioe.org> <jb8p9v$cmn$1@speranza.aioe.org> |
On 12/ 2/11 09:50 AM, jacob navia wrote: > Le 01/12/11 21:38, Alan Curry a écrit : >> In article<jb7sfh$221$1@speranza.aioe.org>, >> jacob navia<jacob@jspamsink.org> wrote: >>> Thanks to everybody tht answered. I think I will go the way >>> Gordon Burditt proposed. >> >> There's another answer that we forgot: >> >> Put the array at the beginning of the struct. Then if the struct is malloced, >> the array inherits its "aligned for anything" property. >> > I can't do that since I do not know how big the array will be. > The user calls me with > > iList.Create(sizeof(double)); > > to create a list of doubles. > > This is a variable length structure, allocated with > > malloc(sizeof(ListElement)+list->ElementSize); > > The data start immediately after the pointer. In that case, wouldn't it have been better to declare char Data[]? But then again, you can't use a flexible array in a nested union. <snip> > The problem is further complicated by the fact that under SPARC > modern versions you do NOT need to align anything since the OS > catches the unaligned trap, and loads the double with 2 instructions. That's an expensive option, or at least it used to be on older processors. The Sun compilers support misaligned access (through the -xmemalign option), but transferring to trap handler is a significant overhead. > Now the problem is that modern versions of gcc (and that machine has > 4.2 installed) follow the recommendations of Oracle (ex Sun) and > emit ldd instead of a sequence of two ld instructions expecting > the OS to trap that. But since that machine has an OS from May > 2002 (imagine that, almost ten years old) that apparently does NOT > catch that unaligned instruction. > > Anyway, this is a general problem since the power PC has probably > similar problems. The joys of portable code! -- Ian Collins
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Alignment problems jacob navia <jacob@spamsink.net> - 2011-12-01 01:05 +0100
Re: Alignment problems Ian Collins <ian-news@hotmail.com> - 2011-12-01 13:15 +1300
Re: Alignment problems pacman@kosh.dhis.org (Alan Curry) - 2011-12-01 02:57 +0000
Re: Alignment problems gordonb.hpln0@burditt.org (Gordon Burditt) - 2011-11-30 21:27 -0600
Re: Alignment problems jacob navia <jacob@spamsink.net> - 2011-12-01 13:38 +0100
Re: Alignment problems pacman@kosh.dhis.org (Alan Curry) - 2011-12-01 20:38 +0000
Re: Alignment problems jacob navia <jacob@spamsink.net> - 2011-12-01 21:50 +0100
Re: Alignment problems Ian Collins <ian-news@hotmail.com> - 2011-12-02 10:27 +1300
Re: Alignment problems Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-12-04 00:23 +0000
Re: Alignment problems Ian Collins <ian-news@hotmail.com> - 2011-12-04 13:31 +1300
Re: Alignment problems ImpalerCore <jadill33@gmail.com> - 2011-12-01 14:34 -0800
Re: Alignment problems "BartC" <bc@freeuk.com> - 2011-12-01 13:46 +0000
Re: Alignment problems Keith Thompson <kst-u@mib.org> - 2011-12-01 14:15 -0800
Re: Alignment problems David Thompson <dave.thompson2@verizon.net> - 2012-01-19 02:44 -0500
Re: Alignment problems "James" <no@spam.invalid> - 2011-12-01 19:43 -0800
Re: Alignment problems "Brain" <Brian@myhome.com> - 2011-12-04 02:47 -0600
Re: Alignment problems Keith Thompson <kst-u@mib.org> - 2011-12-04 08:26 -0800
Re: Alignment problems Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-12-08 00:12 +0200
Re: Alignment problems Keith Thompson <kst-u@mib.org> - 2011-12-07 22:31 -0800
Re: Alignment problems lovecreatesbeauty <lovecreatesbeauty@gmail.com> - 2011-12-08 21:43 -0800
Re: Alignment problems Keith Thompson <kst-u@mib.org> - 2011-12-09 01:31 -0800
Re: Alignment problems Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-12-09 14:15 +0200
csiph-web