From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,8aa51189d42a66a4 X-Google-Attributes: gid1164f8,public X-Google-ArrivalTime: 1993-11-10 07:18:55 PST Path: gmd.de!xlink.net!howland.reston.ans.net!pipex!uunet!olivea!decwrl!pa.dec.com!nntpd.lkg.dec.com!jac.zko.dec.com!btgmax.zko.dec.com!cowan From: cowan@btgmax.zko.dec.com (Ken Cowan) Newsgroups: comp.sys.dec Subject: Re: HELP!! : Unaligned access error on DEC Alpha, $OS == osf1 Date: 10 Nov 1993 15:06:24 GMT Organization: Digital Equipment Corporation Distribution: world Message-ID: <2br01g$idn@jac.zko.dec.com> References: <2blfa2INN4sq@flop.ENGR.ORST.EDU> <1993Nov9.072931.639@acs.eku.edu> Reply-To: cowan@btgmax.zko.dec.com (Ken Cowan) NNTP-Posting-Host: btgmax.zko.dec.com In article <1993Nov9.072931.639@acs.eku.edu>, acssysdsc@acs.eku.edu writes: |>Path: jac.zko.dec.com!pa.dec.com!decwrl!olivea!spool.mu.edu!howland.reston.ans.net!paladin.american.edu!gatech!psuvax1!rutgers!ukma!acs.eku.edu!acssysdsc |>From: acssysdsc@acs.eku.edu |>Newsgroups: comp.sys.dec |>Subject: Re: HELP!! : Unaligned access error on DEC Alpha, $OS == osf1 |>Message-ID: <1993Nov9.072931.639@acs.eku.edu> |>Date: Tue, 9 Nov 93 07:29:31 EST |>References: <2blfa2INN4sq@flop.ENGR.ORST.EDU> |>Organization: Eastern Kentucky University |>Lines: 21 |> |>In article , jtk@atria.com (John T. Kohl) writes: |>> In article , I wrote: |>> |>>> Pointers must be |>>> aligned on 8-byte boundaries to avoid unaligned access problems. |>> |>> Let me rephrase that to make sure it's not misleading. _Storage_ for |>> pointers must be aligned on 8-byte boundaries. To avoid unaligned |>> access problems, pointer _values_ need to be aligned to the natural |>> alignment of the item to which they point. |>> -- |> |>So what does he have to do to fix it? Does C have an align statement or |>directive? |> |>dsc |> |>> John Kohl or |>> working for but not representing: Atria Software |>> --------- |>> What are you pretending not to know? |> It looks like the structure is really: struct foo { int m; /* a field that tracks "mem space" struct NODE n; /* the struct here, not pointer to struct */ } If declared and allocated this way, the compiler will pad or pack the structure, as you tell it and will never generate alignment faults. When declare a pointer: int *mem; then "mem + 1" is the address of the next int. That's not the same as telling the compiler that the next item is a struct NODE. By doing the cast, that says that the place where the next int is supposed to be is really a struct NODE. That's different than saying to go to the place where the next struct NODE should be. When ints are the same size as pointers, both have the same alignment requirements and so both the packed and padded alignments of the struct result in the same memory layout. How to fix it? Either tell the compiler that your struct NODE pointer has a base alignment of 4-bytes (via align(4), I think), or allocate "mem_space" as part of a larger structure, or change "int *mem_space" to "long int *mem_space". This last hack gets back to the sizeof(xxx) = sizeof(pointer) axiom. -- Ken Cowan, ZK2-3/Q8 cowan@rtl.enet.dec.com Digital Equipment Corporation decwrl!rtl!cowan 110 Spit Brook Rd, Nashua, NH 03062