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


Groups > comp.lang.c > #14116

Re: Alignment problems

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: Alignment problems
Date 2011-12-01 13:15 +1300
Message-ID <9jnv91F4d0U40@mid.individual.net> (permalink)
References <jb6gbf$58a$1@speranza.aioe.org>

Show all headers | View raw


On 12/ 1/11 01:05 PM, jacob navia wrote:
> I am trying to test the containers library in different environments
>
> One of those is SUN sparc, that crashes when a double is accessed
> in an address not multiple of 8. I got an access to an old one:
>
> : ~/ccl ; uname -a
> SunOS 5.9 Generic_118558-25 sun4u sparc SUNW,Sun-Fire-V210
>
> Now, I have a list container with elements that
> have this structure:
>
> typedef struct _ListElement {
>       struct _ListElement *Next;
>       char Data[MINIMUM_ARRAY_INDEX]; // Generic storage...
> } ListElement;
>
>
> If I store double data in the "Data" member the machine will
> crash since apparently it is a 32 bit SPARC, and the start of Data
> is NOT aligned to an eight byte boundary.
>
> One solution (albeit very ugly) is:
>
> typedef struct _ListElement {
>       struct _ListElement *Next;
>       double alignment1;
>       char Data[MINIMUM_ARRAY_INDEX]; // Generic storage...
> } ListElement;
>
> This works. The compiler will correctly align "Data" and I
> can safely store doubles into it. But this solutions is VERY
> expensive since for EACH element I am spending 8 bytes
> in alignment...

Some waste is unavoidable, the alignment has to be correct on Sparc.

How about a union of (long) double and char[sizeof(long double]?

> P.S. If anyone knows that system, gcc warns me
>
> warning: implicit declaration of function 'snprintf'
>
> I do include stdio.h...
>
> What else should I include for getting snprintf?

I think there was a problem with the header on that old OS version.

-- 
Ian Collins

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


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