(none)

ghoti at BOURBAKI.MIT.EDU ghoti at BOURBAKI.MIT.EDU
Mon Oct 24 15:28:11 AEST 1988


I was writing a program and defined a struct foo as follows:

	struct foo {
		int number ;
		int (*f)() ;
		} ;
It occurred to me that it would be useful to be able to define a function
of the following sort:

struct foo *
tensor_fooze(struct foo foo1,struct foo foo2)
{
   struct foo * spec = (struct foo *) malloc(sizeof(struct foo)) ;
	spec->number = lcm(foo1.number,foo2.number) ;
   etc.

The catch is that there doesn't seem to be a natural way to define
spec->fn [sorry, above I should have written int (*f)() fn ; in the
definition of struct foo ] unless I want to let it be a pointer to
a function already existing in the C code. I could get around this
if there were any kind of facility such as 
spec->fn = lambda(x){ function body }, but that isn't C . It seems like
a desirable feature but how hard is it to implement such a feature ?
Alternatively, is there an extension to the C language (e.g. in C++)
which lets one pull a stunt like this ?

Please address your  replies to me directly since I don't subscribe to
this mailing list. Thanks.

Allan Adler
ghoti at cauchy.mit.edu



More information about the Comp.lang.c mailing list