Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: cowan@btgmax.zko.dec.com (Ken Cowan)
Subject: Re: HELP!! : Unaligned access error on DEC Alpha, $OS == osf1
Date: 10 Nov 1993 15:06:24 GMT	[thread overview]
Message-ID: <2br01g$idn@jac.zko.dec.com> (raw)
In-Reply-To: 1993Nov9.072931.639@acs.eku.edu


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> <CG6J69.1rt@atria.com> <CG6wLL.4MF@atria.com>
|>Organization: Eastern Kentucky University
|>Lines: 21
|>
|>In article <CG6wLL.4MF@atria.com>, jtk@atria.com (John T. Kohl) writes:
|>> In article <CG6J69.1rt@atria.com>, 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 <jtk@atria.com> or <jtkohl@mit.edu>
|>> 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


  parent reply	other threads:[~1993-11-10 15:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-11-08 12:50 HELP!! : Unaligned access error on DEC Alpha, $OS == osf1 Joseph Jacob
1993-11-08 15:32 ` John T. Kohl
1993-11-08 20:22   ` John T. Kohl
1993-11-09 12:29     ` acssysdsc
1993-11-09 20:26       ` Karen Kolling
1993-11-09 20:45         ` Karen Kolling
1993-11-10 15:06       ` Ken Cowan [this message]
1993-11-09  4:26 ` Karen Kolling
1993-11-09 17:06   ` Bruce O'Neel
1993-11-09 23:06     ` HELP!! : Unaligned access error on DEC John Lovell
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox