[LLVMdev] Evaluation of offsetof() macro

Joerg Sonnenberger joerg at britannica.bec.de
Sat Jan 3 23:49:57 PST 2015


On Sat, Jan 03, 2015 at 06:01:26PM -0800, Vadim Chugunov wrote:
> > Do you start from offsetof() or the expanded form? For various reasons,
> > it is normally defined to use __builtin_offsetof, since the problems you
> > have run into also stop the "legacy" C version from being appropoiate
> > for C++ as it doesn't create an ICE.
> >
> 
> I start with a macro, but I was considering expanding it to pointer
> arithmetic, to avoid creating special operators such as
> __builtin_offsetof.   Would that be considered a bad idea?

You found the problems with dealing with pointer arithmetic already.
Dealing with the (existing) builtin is much easier. It also helps to
give some diagnostics for illegal use, e.g. non-POD arguments in C++
mode.

Joerg



More information about the llvm-dev mailing list