Hi Quin,

sorry, another  idea I noted down some time ago which I would like
to mention. 

> > 
> > - use it only in limited contexts where you do not need to know
> >   the type (e.g. this works for goto labels) or for a basic
> >   counted_by attribute that only takes an identifier as we have it now.

A version of this is to allow taking the address of the member, but
give it the type void*.  The user can then convert it to the right type
(and we could warn later if the cast goes to the wrong type).

struct foo {
  int z;
  float f;
}

typedef struct counter_t[5][10];

struct bar {
  char *array __attribute__ ((counted_by ( (*(counter_t)&.y)[1][3].z + 4 );
  struct foo y[5][10];
}

This could also be used together with the function idea:

struct bar {
  char *array __attribute__ (( counted_by ( bar_count(&.y) ));
  struct foo y[5][10];
}


This would be simple to implement and do the job.

Martin

Reply via email to