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