Path: utzoo!mnetor!uunet!ccicpg!puivax!ian From: ian@puivax.UUCP (Ian Wilson) Newsgroups: comp.lang.c Subject: Re: ANSI C idea: structure literals Message-ID: <139@puivax.UUCP> Date: 3 Mar 88 15:25:26 GMT References: <56@vsi.UUCP> <1988Feb28.130526.4147@jarvis.csri.toronto.edu> <2804@haddock.ISC.COM> Reply-To: ian@puivax.UUCP (Ian Wilson) Organization: Philips Ultrasound International, Santa Ana, CA. Lines: 45 Keywords: ANSI, structure literals In article <2804@haddock.ISC.COM> karl@haddock.ima.isc.com (Karl Heuer) writes: >In article <1988Feb28.130526.4147@jarvis.csri.toronto.edu> flaps@dgp.toronto.edu (Alan J Rosenthal) writes: >>In article <56@vsi.UUCP> friedl@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