home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16437 < prev    next >
Encoding:
Text File  |  1992-11-12  |  1.2 KB  |  29 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!utcsri!torn!utzoo!telly!druid!darcy
  3. From: darcy@druid.uucp (D'Arcy J.M. Cain)
  4. Subject: LHS Casting
  5. Summary: Is it ever OK/right to have a cast on the left?
  6. Message-ID: <1992Nov13.050054.28251@druid.uucp>
  7. Date: Fri, 13 Nov 1992 05:00:54 GMT
  8. Organization: D'Arcy Cain Consulting
  9. Lines: 18
  10.  
  11. I came across some of the ugliest code I have seen in a long time recently.
  12. At one point there is a pointer to char that is declared as a pointer to
  13. int.  To get an address within this block of bytes the programmer does:
  14.  
  15. (int *) charptr = intptr + (OFFSET/2);
  16.  
  17. Well of course this is bad.  The FAQ (question 2.13) shows another case
  18. where the wrong code has the cast on the left hand side of an assignment.
  19. Is it safe to say that there is never any case where a cast belongs on
  20. the LHS of an assignment?  It seems to me that at best such code is
  21. clumsy and could be better written some other way and that probably
  22. it is wrong and the compiler is always free to reject such constructs.
  23.  
  24. -- 
  25. D'Arcy J.M. Cain (darcy@druid.com)  |
  26. D'Arcy Cain Consulting              |   There's no government
  27. Toronto, Ontario, Canada            |   like no government!
  28. +1 416 424 2871          DoD#0082   |
  29.