[cfe-commits] r41613 - in /cfe/trunk: AST/Expr.cpp Sema/Sema.h Sema/SemaExpr.cpp include/clang/AST/Expr.h include/clang/AST/StmtVisitor.h include/clang/Basic/DiagnosticKinds.def

Neil Booth neil at daikokuya.co.uk
Thu Aug 30 15:55:56 PDT 2007


Chris Lattner wrote:-

> >I thought it would be instructive to figure that out yourself :)
> >
> >struct s { struct { int t; } x[2]; };
> >int f (void) { return offsetof (struct s, x->t); }
> 
> Are you sure that's valid?  C99 has a maddeningly brief discussion of  
> what is valid in offsetof.  By this logic, wouldn't offsetof (struct  
> s, x+1) also be valid?

Hmm, I guess it would.  Yuk.

The std for this is written in ridiculously vague language
that could be read as intending only a single identifier as the
second argument.  See e.g. (last one by yours truly):

http://groups.google.co.jp/group/comp.std.c/browse_thread/thread/c5e4e9633777ea05/7c4fd8b87d70ca2a?lnk=gst&q=offsetof&rnum=1&hl=en#7c4fd8b87d70ca2a

http://groups.google.co.jp/group/comp.std.c/browse_thread/thread/771a804a75eb9969/e83b944fa1154416?lnk=gst&q=offsetof&rnum=4&hl=en#e83b944fa1154416

http://groups.google.co.jp/group/comp.std.c/browse_thread/thread/590ef7e481a20c8e/4d10e2b8d3cfd955?lnk=gst&q=offsetof+neil&rnum=1&hl=en#4d10e2b8d3cfd955

In each thread different members of the C committee have said that
only an identifier was intended.  To me that only begs the question
of why the language is so opaque - surely easier to just say it
shall be an identifier?

But your example has convinced me that restricting this offsetof to
just an identifier is probably a good idea - accepting generic
expressions can get out of control.

FWIW Viro had sparse accept ->

	http://lkml.org/lkml/2007/6/24/143

Neil.



More information about the cfe-commits mailing list