home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16600 < prev    next >
Encoding:
Internet Message Format  |  1992-11-16  |  1.7 KB

  1. Path: sparky!uunet!olivea!spool.mu.edu!darwin.sura.net!gatech!concert!sas!mozart.unx.sas.com!sasghm
  2. From: sasghm@theseus.unx.sas.com (Gary Merrill)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: LHS Casting
  5. Message-ID: <BxtEqM.2qz@unx.sas.com>
  6. Date: 16 Nov 92 15:23:10 GMT
  7. References: <1992Nov13.050054.28251@druid.uucp>
  8. Sender: news@unx.sas.com (Noter of Newsworthy Events)
  9. Organization: SAS Institute Inc.
  10. Lines: 25
  11. Originator: sasghm@theseus.unx.sas.com
  12. Nntp-Posting-Host: theseus.unx.sas.com
  13.  
  14.  
  15. In article <1992Nov13.050054.28251@druid.uucp>, darcy@druid.uucp (D'Arcy J.M. Cain) writes:
  16. |> I came across some of the ugliest code I have seen in a long time recently.
  17. |> At one point there is a pointer to char that is declared as a pointer to
  18. |> int.  To get an address within this block of bytes the programmer does:
  19. |> 
  20. |> (int *) charptr = intptr + (OFFSET/2);
  21. |> 
  22. |> Well of course this is bad.  The FAQ (question 2.13) shows another case
  23.  
  24. It's not only bad, it is a violation of ANSI.  See Section 3.3.4,
  25. note 41 ("A cast does not yield an lvalue. ...")  Some older C
  26. compilers used to accept this nonsense.  I cannot lay my hands on
  27. a precise reference at the moment, but there was an issue of _Dr.
  28. Dobbs_ some time in '85 or '86 in which a paper (to the ANSI C
  29. committtee) written by Francis Lynch and me was reprinted almost in
  30. its entirety as part of a column on the standardization of C.  In
  31. that paper a number of compelling arguments are offered against
  32. allowing a cast to be an lvalue.  If you can find the appropriate
  33. issue of the magazine, you might be interested in these arguments.
  34.  
  35. -- 
  36. Gary H. Merrill  [Principal Systems Developer, C Compiler Development]
  37. SAS Institute Inc. / SAS Campus Dr. / Cary, NC  27513 / (919) 677-8000
  38. sasghm@theseus.unx.sas.com ... !mcnc!sas!sasghm
  39.