From owner-freebsd-arm@FreeBSD.ORG Tue Sep 3 12:31:14 2013 Return-Path: Delivered-To: freebsd-arm@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 7343DA3D for ; Tue, 3 Sep 2013 12:31:14 +0000 (UTC) (envelope-from tuexen@freebsd.org) Received: from mail-n.franken.de (drew.ipv6.franken.de [IPv6:2001:638:a02:a001:20e:cff:fe4a:feaa]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 0B5E321F5 for ; Tue, 3 Sep 2013 12:31:14 +0000 (UTC) Received: from [192.168.1.6] (p5481B468.dip0.t-ipconnect.de [84.129.180.104]) (Authenticated sender: macmic) by mail-n.franken.de (Postfix) with ESMTP id 943E11C0C0BD8 for ; Tue, 3 Sep 2013 14:31:11 +0200 (CEST) From: Michael Tuexen Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: A simple question about C... Message-Id: Date: Tue, 3 Sep 2013 14:31:11 +0200 To: freebsd-arm@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) X-Mailer: Apple Mail (2.1508) X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Porting FreeBSD to the StrongARM Processor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Sep 2013 12:31:14 -0000 Dear all, I'm trying to get a C program (packetdrill) running FreeBSD r254973 on a Raspberry Pi. Since tests are failing, I wrote the little C program: #include #include #include int main(void) { uint8_t byte[] =3D {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b}; uint32_t i, n, *p; for (i =3D 0; i <=3D 8; i++) { p =3D (uint32_t *)(byte + i); memcpy(&n, byte + i, sizeof(uint32_t)); printf("p =3D %p, *p =3D %08x, n =3D %08x.\n", (void = *)p, *p, n); } return (0); } It produces the following output: p =3D 0xbfffec48, *p =3D 03020100, n =3D 03020100. p =3D 0xbfffec49, *p =3D 00030201, n =3D 04030201. p =3D 0xbfffec4a, *p =3D 01000302, n =3D 05040302. p =3D 0xbfffec4b, *p =3D 02010003, n =3D 06050403. p =3D 0xbfffec4c, *p =3D 07060504, n =3D 07060504. p =3D 0xbfffec4d, *p =3D 04070605, n =3D 08070605. p =3D 0xbfffec4e, *p =3D 05040706, n =3D 09080706. p =3D 0xbfffec4f, *p =3D 06050407, n =3D 0a090807. p =3D 0xbfffec50, *p =3D 0b0a0908, n =3D 0b0a0908. So everything is fine when reading the 4 byte long uint32_t on a 4-byte = aligned address. Results are strange (at least for me), when the address is not = 4-byte aligned. There is no difference between clang and gcc. Can I only = dereference properly aligned pointers? Is the above expected or is it a bug in the = compiler? Best regards Michael=