It is currently Mon, 25 Sep 2023 12:25:47 GMT

Author Message
 Help: Unaligned access?
I have some C++ code for use in Windows and UNIX.  It compiles fine in
UNIX (DEC) but gives  "Unaligned access..." errors when I try to run
it.  If I compile with the -misalign option most of the errors go away.
The ones that remain occur when calling the constructor of a class which
looks like this:

CTable::CTable(String * path, int nTable) // where String is a library

Constructing this class is one of the first steps in the main function.
Any ideas on what's causing this or what I could do to figure out what
is causing it?  I have stepped through the constructor of another of my
classes to see if this might be a problem everywhere, but it seems to
only happen in this one.


 Sat, 17 Feb 2001 03:00:00 GMT   
 Help: Unaligned access?
The problem is most likely unaligned data.  If you have a data structure
which has 32-bit data on a non-32-bit memory boundary then the Unaligned
access error can be reported by many RISC cpu's.  The same goes for any data
size > 8 bits.  16-bit data must be 16-bit aligned, 32-bit data must be
32-bit aligned, etc.

Usually, the compiler will take care of the alignment stuff for you when you
create your data structures. But some programmers use the equivalent to
#pragma pack(1) which forces the compiler to pack all data and keeps the
compiler from aligning the data as needed by the CPU.  My first thought is
to find all of the pack pragma's and remove them if you can.  If you can't
remove them then change your data structures so that all data is properly

By using the -misalign option, you are slowing down your code tremendously.
Every data access that is > 8 bits is being accessed as separate 8 bit
values.  So a 32-bit access is being broken down by the compiler into 4
8-bit accesses.  So even though that helps, you don't want to do that if you
can fix it.


 Sun, 18 Feb 2001 03:00:00 GMT   
 Help: Unaligned access?
In message <> pj park wrote:

It sounds like the code does some weird pointer conversions, and makes
assumptions about the underlying hardware that aren't statisfied for the
alpha. It could be hard to straighten things out.

A first bet... your costructor calls a library function wit a misaligned
pointer... and the library function isn't compiled with the -misalign

You can check the behaviour by running your program from within a de{*filter*},
I use dbx or xdb usually; it could be that your system has a window based
de{*filter*}. If your crashing program created a "core" file you can do a post-
mortem analysis by doing
        xdb <program> core
which should give a stacktrace... Much more usefull functions of xdb become
available when compiling and linking with the -g flag.

Peter Roozemaal

 Mon, 19 Feb 2001 03:00:00 GMT   
   [ 3 post ] 

Similar Threads

1. Unaligned access (bus error) on Solaris on global variable

2. Signal handler for unaligned access: emulate and continue?

3. Signal handler for unaligned access: emulate and continue?

4. Fixing unaligned access Solaris 2.3

5. Wanted: Unaligned access exceptions

6. unaligned access 3

7. unaligned access?!

8. Get GDB to stop at Unaligned access

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software