home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 18732 < prev    next >
Encoding:
Text File  |  1992-12-21  |  1.1 KB  |  27 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!europa.asd.contel.com!howland.reston.ans.net!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!ames!saimiri.primate.wisc.edu!sal.wisc.edu!alan
  3. From: alan@sal.wisc.edu (Alan Watson)
  4. Subject: Re: Question to test general C knowledge
  5. Message-ID: <1992Dec21.001419.20865@sal.wisc.edu>
  6. Organization: Space Astronomy Lab, Madison WI
  7. References: <1992Dec14.164400.59891@ns1.cc.lehigh.edu> <1992Dec17.190025.11325@athena.mit.edu> <1992Dec20.234400.11271@thunder.mcrcim.mcgill.edu>
  8. Date: Mon, 21 Dec 1992 00:14:19 GMT
  9. Lines: 16
  10.  
  11. In article <1992Dec20.234400.11271@thunder.mcrcim.mcgill.edu> mouse@thunder.mcrcim.mcgill.edu (der Mouse) writes:
  12.  
  13. [ On whether to replace i % 4 with i & 3 and i / 2 with i >> 1: ]
  14.  
  15. >The compiler often cannot tell whether it is correct to do so.  If the
  16. >variable is declared signed (probably implicitly), but cannot in fact
  17. >be negative at that point
  18.  
  19. In this case I would usually write one of:
  20.  
  21.     (unsigned) i % 4
  22.     (unsigned) i / 2
  23.  
  24. which give the compiler all the information it needs.  This technique
  25. is one of the few ways in C that one can pass optimization hints to the
  26. compiler.
  27.