Quoting "Joseph S. Myers" <jos...@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.)

how about:

typedef struct
{
  void *p;
} cumulative_args_t;

or maybe for more efficiency:

#ifdef __GNUC__
#define ATTRIBUTE_TRANSPARENT_UNION __attribute__((transparent_union))
#else
#define ATTRIBUTE_TRANSPARENT_UNION
#endif

typedef union ATTRIBUTE_TRANSPARENT_UNION { void *p; } cumulative_args_t;

static inline struct x86_cumulative_args *
x86_get_cumulative_args (cumulative_args_t arg)
{
  return (struct x86_cumulative_args *) arg.p;
}

Reply via email to