Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!uwm.edu!linac!att!ucbvax!torolab6.vnet.ibm.com!mccrady From: mccrady@torolab6.vnet.ibm.com ("++Don;") Newsgroups: comp.lang.c Subject: offsetof() Message-ID: <9105211239.AA22229@ucbvax.Berkeley.EDU> Date: 21 May 91 12:36:37 GMT Article-I.D.: ucbvax.9105211239.AA22229 Sender: daemon@ucbvax.BERKELEY.EDU Lines: 20 > That is, ((size_t)&(((type *)0)->member)) or something like that. > I had thought the expression is evaluated at run-time because > the following expression is not accepted: > char a_array[offsetof(type,member)]; If offsetof() is defined as you say, then its use in the array index is illegal according to ANSI. ANSI requires that the array dimension be an integral constant expression. Section 3.5 states: Cast operators in an integral constant expression shall only convert arithmetic types to integral types, except as part of an operand to the sizeof operator. Your compiler's definition of offsetof() converts pointer types to integral types, and thus violates the above constraint. I know that's not very helpful to you, but it at least answers your question. ++Don;