[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Long double alignment test



Mentors,

This may be a full-on d-devel question, but I'll start out here.

I'm maintaining GNU Smalltalk, which is having problems building on
most 64-bit platforms. I'm having difficulty tracking these problems
down, so I'm asking for some assistance from anyone who has access to
these platforms (any DD, I believe).

The issue is with a test for long double alignment which reports an
incorrect value on ia64 (and probably other archs). On a RedHat
mailing list I have found the following code which is claimed to
correctly detect long double alignment:

http://sources.redhat.com/ml/autoconf/1999-07/msg00002.html

struct foo {
    union align {
        double d;
        long l;
        void *p;
    } u;
    char c;
};

int main() {
    struct foo f[2];

    printf("sizeof(foo)=%ld\n", (long) sizeof(struct foo));
    printf("sizeof(align)=%ld\n", (long) sizeof(union align));
    printf("sizeof(f2)=%ld\n", (long) sizeof(f));

    if( 2*sizeof(union align) != sizeof(f) ) {
        printf("union may be aligned on %ld byte boundaries.\n",
            (long)(sizeof(struct foo) - sizeof(union align)));
        return 1;
    }

    printf("union must be aligned on %ld byte boundaries.\n",
        (long)sizeof(union align));
    return 0;
}

Anyone know if this works? Could someone please run this on each of
the archs we support (particularly ia64) and report the results to me?

Does anyone have any better code for discovering alignment? I'm
surprised this isn't common enough that there would be a stock
solution.

Thanks in advance,

-- Brett

Attachment: signature.asc
Description: Digital signature


Reply to: