A useful construct for C ?

Ron Natalie <ron> ron at brl-tgr.ARPA
Thu Feb 7 07:32:44 AEST 1985


> I would like to sample the community on a possibly useful construct
> 	typeof(foo)
> which is the type of expression foo.  It is similar in utility to sizeof().
> 
>	....
>
> It would be nice to be able to say:
> 	int *foo;
> 	foo = (typeof(foo))malloc(sizeof(*foo) * nelts);
> 

Well first, would the C standard group's (void *)'s help here?

Actually, MALLOC really should know what alignment requirement is
required.  Right now it just takes the least common multiple of
all data types.  Should a similar builtin function (I'll use a
silly name here to avoid confusion:

	foo = (typeof foo) malloc(sizeof(*foo)*nelts, rons_typeof foo);

Where rons_typeof would yield something like an enum that could be checked
for in the Malloc routine.

-Ron



More information about the Comp.lang.c mailing list