Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: structure constant assignment Message-ID: <1989Oct5.180543.8126@utzoo.uucp> Organization: U of Toronto Zoology References: <6990@cs.utexas.edu> Date: Thu, 5 Oct 89 18:05:43 GMT In article <6990@cs.utexas.edu> paul@cs.utexas.edu (Supoj Sutanthavibul) writes: >C syntax does nota allow construction of structure constants) >Why? Because. Sorry, that may sound unhelpful, but that really is the answer. It's just never been a feature of C. >Does standard C allow assignment of structure constant as >in the following example? ... > q = (Coord){ 0, 0 }; No. There are problems with the design of such a feature, which have been gone into at some length on this group before. What is the type of `{ 0, 0 }'? If the cast is mandatory, then this is the only place in the language where that's true, so it isn't really a cast but something else. There are other ways of handling it... but in general, it's not a feature of ANSI C because of limited usefulness and lack of implementation experience. Try this: main() { Coord q; static Coord zero = { 0, 0 }; /* this is just an initialization */ q = zero; /* this is legal */ } This won't work for non-constant values, of course. -- Nature is blind; Man is merely | Henry Spencer at U of Toronto Zoology shortsighted (and improving). | uunet!attcan!utzoo!henry henry@zoo.toronto.edu