This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFC: Defining and using target vectors


On Thu, 18 Nov 2010, Joern Rennecke wrote:

> Quoting "Joseph S. Myers" <joseph@codesourcery.com>:
> 
> > You can perfectly well do type safety without using void *.
> > 
> > struct cumulative_args;
> > type hook(struct cumulative_args *arg);
> > 
> > 
> > static inline struct x86_cumulative_args *
> > x86_get_cumulative_args (struct cumulative_args *arg)
> > {struct cumulative_args *
> >  return (struct x86_cumulative_args *) arg;
> > }
> 
> But then you run into implementation-defined behaviour for the casts from/to
> struct cumulative_args * .  E.g. an implementation could decide to chop
> off some bits at the bottom because struct cumulative_args is supposed to
> have extra alignment because of the members it contains - or because of an
> md5hash hash collision with the name of the developer's favourite pet.
> (Properly documented, of course.)

struct cumulative_args could always be defined (automatically) to contain 
a union between the target structures, so that casting to a pointer to the 
union then to a pointer to one of those structures is well defined.  
Though it seems more natural for struct cumulative_args to be the first 
element of the target structures, and in the multi-target case to contain 
a magic number that can be checked in the inline function (at least when 
checking is enabled) to make sure the structure is one for the right 
target.

> how about:
> 
> typedef struct
> {
>  void *p;
> } cumulative_args_t;

Yes, as I said there are many possible approaches that are type-safe (or 
at least safer than having void * parameters to the hooks) and do not 
require splitting these hooks into a separate vector.

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]