From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <48f5733d46f1cab95f848c587ecb6e55.axp-list@archive.invalid> X-Archive-Original-Message-ID: <1777.229T629T7444030@student.tuwien.ac.at> Date: 17 Oct 97 12:24:12 +0100 From: Christoph Zens Subject: Re: Unaligned traps... In-Reply-To: >However I also get >Oct 16 05:43:30 where kernel: netstat(15228): unaligned trap at >0000000000000029: 000000011ffff88c 2d 10 >Perhaps show a before and after of the kind of error (like is there a >sample program that will cause these errors and then the solution program?) If your program defines something like: long *foo; char bar[32]; and then attempts to do this: foo = (long *)&bar[3]; *foo = 1234; then you will get an unaligned trap at runtime. In a nutshell: You should not try to do longword accesses at an odd memory address. The best (and safest) way is to align every access on a byte-address that is an integral multiple of the byte-size that you deal with. For the above example, this leads to: foo = (long *)&bar[4]; *foo = 1234; on x86-based machines ("long" is four bytes in length), BUT: foo = (long *)&bar[8]; *foo = 1234; for alpha-based maschines, where "long" consists of eight bytes. Perhaps you want to change some variable declarations within your code from "long" to "int", as "int" on the alpha is four bytes long and thus, could eventually remove your unaligned trap. Another frequently seen thing at compile time is: "warning: casting pointer to integer of different size" Every program, that makes the assumption that an "integer" is the same size as a pointer, runs into such problems on an alpha. Things to watch out for: int foo; something *bar; foo = (int)bar; To correct this, you will have to use "long" to declare "foo" and cast the pointer to long which has the same size as the pointer itself (eight bytes). hope that helps. -- _ _ // \X/ Christoph Zens Hofstaeter's law: It takes always longer than you think, even if you take into account Hofstaeter's law. -- To unsubscribe: send e-mail to axp-list-request@redhat.com with 'unsubscribe' as the subject. Do not send it to axp-list@redhat.com