Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!husc6!uwvax!umn-d-ub!nic.MR.NET!shamash!nis!ems!questar!midgard!dal From: dal@midgard.mn.org (Dale Schumacher) Newsgroups: comp.lang.c Subject: Re: A cast pointer is NOT an lvalue!? (ANSI C) Keywords: X3J11, pointers, cast, lvalue Message-ID: <482@midgard.mn.org> Date: 11 Oct 88 22:15:22 GMT References: <479@midgard.mn.org> <8663@smoke.ARPA> Reply-To: dal@syntel.UUCP (Dale Schumacher) Organization: The Midgard Realm, St Paul MN Lines: 43 In article <8663@smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: |In article <479@midgard.mn.org> dal@syntel.UUCP (Dale Schumacher) writes: |> value = *((long *) argp)++; | |A cast is the same as assignment to an unnamed temporary variable. |The ++ in your example would have to increment the temporary variable, |not the original variable argp. That is clearly not what you wanted. Ok. This makes sense. Since my posting I also discussed this with Shane McCarron, who explained problems involving pointers of different sizes and the possibility of distinct storage for different types, which brings up a later question with Chris Torek's response. |Anyway, you should be using either the old or the new | macros to pick up arguments from a variable argument list. |What you were trying to do cannot be done portably any other way. The printf()/scanf() code was written before I implemented macros and I haven't gone back to change it yet. I probably should. In article <13912@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: |In article <479@midgard.mn.org> dal@midgard.mn.org (Dale Schumacher) writes: | |>As a clearer example of what I consider valid use of a cast |>pointer, consider the following: | |But this *is* valid: | |> struct big_thing { /* several elements */ } big, *bp; |> char *p; |[...] |> if(p = malloc(sizeof(struct big_thing))) |> *((struct big_thing *) p) = big; |> |>... Why do I need to assign the cast value to an intermediate in |>order to dereference it and assign something to it's contents? | |You do not. The result of a cast is NEVER an rvalue, but the result of |an indirection *is* an lvalue. Is this really legal in X3J11? If an implementation stores different object types in different areas of memory, then wouldn't that fail also? How would one implement malloc() on such a machine?