Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Casting the lvalue Message-ID: <1990Mar6.221457.6801@utzoo.uucp> Organization: U of Toronto Zoology References: <1025@manta.NOSC.MIL> Date: Tue, 6 Mar 90 22:14:57 GMT In article <1025@manta.NOSC.MIL> psm@manta.nosc.mil.UUCP (Scot Mcintosh) writes: >The following seems to be illegal... >(int)array[1] = 5; >while this appears to be ok: >*(int *)&array[1] = 5; > >Question: why is the first form illegal... Why should it be legal? What does it *mean*? To treat array[1] as if it were an int? What if it's not the same size or at the same alignment? If what you *mean* is to take its address, treat that as the address of an int, and operate on the int that (you hope) is there, that sounds like the second form to me. >and is there >a more 'elegant' way than the second form to accomplish >the same thing? Um, just what are you trying to accomplish? If what you're trying to do is what the second form does, then no, there is no real alternative to the second form (barring `*(int *)(array+1)', a minor variation on the same theme). -- MSDOS, abbrev: Maybe SomeDay | Henry Spencer at U of Toronto Zoology an Operating System. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu