Newsgroups: comp.lang.c Path: utzoo!utgpu!jarvis.csri.toronto.edu!dgp.toronto.edu!flaps From: flaps@dgp.toronto.edu (Alan J Rosenthal) Subject: Re: ANSI C idea: structure literals Message-ID: <1988Feb28.130526.4147@jarvis.csri.toronto.edu> Keywords: ANSI, structure literals Organization: University of Toronto References: <56@vsi.UUCP> Distribution: comp Date: Sun, 28-Feb-88 13:05:26 EST In article <56@vsi.UUCP> friedl@vsi.UUCP (Stephen J. Friedl) writes: > struct foo *table[] = { > & { "Bill", 25 }, > & { "Jim", 10 }, > & { "Bob", 40 }, > }; > > Where the compiler sees the & before the {initializer}, it puts >the {struct} somewhere and throws the pointer into the table. This is good. It is an analogue of what happens with strings. It would be good to extend this to arrays and other things. For example, why not be able to write "&3" to get a pointer to int which points to a 3? (This is currently achievable by the non-portable (int *)"\0\0\0\003".) The basic advantage of this is it reduces the need for temporary variables, which are generally a Bad Thing. This is not as bad an addition as some of the ANSI things because there is semi-precedent with strings. Unfortunately, this doesn't seem to allow creating, say, a short in this manner, because you can't specify shorts in expressions. Any attempt to fix this would probably be a very bad addition (such as differentiating "&(short)3" from "&3" even though "(short)3" and "3" usually are identical). (Of course, they're already different when sizeof is used on them, but this is already ugly.) ajr -- If you had eternal life, would you be able to say all the integers?