[comp.lang.c++] Odd behavior of offset macro with Cfront 2.0

brucec@phoebus.phoebus.labs.tek.com (Bruce Cohen;;50-662;LP=A;) (08/21/90)

Can anyone tell me why cfront 2.0 gives me the following error messages:

"test.c", line 16: sorry, not implemented: general initializer in initializer list
"test.c", line 16: sorry, not implemented: general initializer in initializer list


with the program:

/* test offset macro with cfront 2.0 */
#include <stdio.h>

typedef unsigned int size_t;
#define offsetof(ty,mem) ((size_t)&(((ty*)0)->mem))

struct tester
{
    int one;
    int two;
} test;
typedef struct tester testType, *testPtr;

struct PrintStruct
{
    char* name;
    int   number;
} Print[] = 
{
    {
        "One",
        offsetof(testType, one)
    },
    {
        "Two",
        offsetof(testType, two)
    }
};

main()
{
    int i;
    for (i = 0; i < sizeof(Print) / sizeof(Print[0]); i++)
    {
        printf("%s = %d\n", Print[i].name, Print[i].number);
    }
}

I first found the problem using the XtOffset macro from the X toolkit
intrinsics, but the standard Cfront macro (modulo one level of indirection
in the macro itself) gives me the same result.  I've pasted the macro
definition into the test file, and it compiles and runs with g++ 1.37, or
C (sun4 native compiler or gcc 1.37)

My guess is that for some reason the compiler thinks that the macro
expansion results in a constructor call in the initializer, which is, of
course, a no-no.  But that seems wrong; the macro should result in a
compile-time constant expression, shouldn't it?
--
---------------------------------------------------------------------------
NOTE: USE THIS ADDRESS TO REPLY, REPLY-TO IN HEADER MAY BE BROKEN!
Bruce Cohen, Computer Research Lab        email: brucec@tekcrl.labs.tek.com
Tektronix Laboratories, Tektronix, Inc.                phone: (503)627-5241
M/S 50-662, P.O. Box 500, Beaverton, OR  97077