structure constant assignment
Henry Spencer
henry at utzoo.uucp
Fri Oct 6 04:05:43 AEST 1989
In article <6990 at cs.utexas.edu> paul at 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 at zoo.toronto.edu
More information about the Comp.lang.c
mailing list