ANSI C idea: structure literals

Ian Wilson ian at puivax.UUCP
Fri Mar 4 01:25:26 AEST 1988


In article <2804 at haddock.ISC.COM> karl at haddock.ima.isc.com (Karl Heuer) writes:
>In article <1988Feb28.130526.4147 at jarvis.csri.toronto.edu> flaps at dgp.toronto.edu (Alan J Rosenthal) writes:
>>In article <56 at vsi.UUCP> friedl at vsi.UUCP (Stephen J. Friedl) writes:
>>>        struct foo      *table[] = {
>>>                & { "Bill",  25 },
>>
>
>(I'll use backquotes `` in running text to avoid colliding with C notation.)
>
>I like the concept of unnamed remote objects, but I'm uneasy about allowing
>`&` to apply to a non-lvalue.  I would prefer a more explicit syntax: let's
>postulate a keyword `remote` that looks like a function call with two
>arguments, the first of which is a type name, and the second an initializer;
>the result is an unnamed lvalue of the specified type and value.  Thus,
>Only on a broken compiler.  In C, `sizeof((short)3)` returns sizeof(int).
>(Because `(short)3` is not an lvalue.)

Another place where anonymous objects would be handy is for functions
embedded in data structures. For example:

	struct {
		char *name;
		int (*handler)();
	} table[] =
	{
		{"fred", &remote( int (*)(), { return 6; }},
		-- etc ---
	};

These functions have similar properties to the struct example
originally quoted: their names are never needed, they have to
be constructed somewhere distant from where they are required,
their names must be chosen so as not to conflict with anything
else, and so on.

Presumably, in order to be able to specify formal parameters to
these anonymous functions the `remote' syntax would have to be
extended:

	(*(&remote( (*)(char * x), {printf("%s\n", x);} )));

Perhaps it would be better to acknowledge what `remote' is trying
to be and call it `lambda' .... (:-))

	ian wilson



More information about the Comp.lang.c mailing list