From f5ae93b5b022542e888ae5ff68f1cc1d02c6cd04 Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Mon, 7 Oct 2013 10:36:43 +0000 Subject: [PATCH] another attempt to check word alignment git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37203 72102866-910b-0410-8b05-ffd578937521 --- config/config.align.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/config/config.align.c b/config/config.align.c index 720a4ddda..e9961de80 100644 --- a/config/config.align.c +++ b/config/config.align.c @@ -10,18 +10,34 @@ int main () { - char buf[32]; - char *ptr = buf; - short sval = 4; - int ival = 3; - if (0 == ((int)ptr % 2)) - { - ptr++; - } - *(short *)ptr = sval; - *(int *)(ptr + sizeof(short)) = ival; - ptr[sizeof(short) + sizeof(int)] = 0; - puts (ptr); /* force compiler not to optimise out the above assignments */ - exit (0); + char *buf = malloc(30); + void *v; + int *sp; + int *sq; + int *ip; + int *iq; + int i; + + for (i = 0 ; i < 30; i++) + { + buf[i] = i; + } + v = buf; + + sp = (short*)(v + 1); + sq = (short*)(v + 2); + if (*sp == *sq) + { + return 1; + } + + ip = (int*)(v + 1); + iq = (int*)(v + 2); + if (*ip == *iq) + { + return 1; + } + + return 0; }