home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / c / 12368 < prev    next >
Encoding:
Text File  |  1992-08-14  |  1.4 KB  |  44 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!baillie
  3. From: baillie@cs.mu.OZ.AU (Stephen Baillie)
  4. Subject: Re: Paranoia, side effects, and optimizing compilers
  5. Message-ID: <9222819.26380@mulga.cs.mu.OZ.AU>
  6. Organization: Computer Science, University of Melbourne, Australia
  7. References: <DAVIS.92Aug14120003@pacific.mps.ohio-state.edu>
  8. Date: Sat, 15 Aug 1992 09:26:54 GMT
  9. Lines: 33
  10.  
  11. davis@pacific.mps.ohio-state.edu ("John E. Davis") writes:
  12.  
  13. >Hi,
  14.  
  15. >   Consider:
  16.  
  17. >      unsigned char *p;   
  18. >   
  19. >      while (1)
  20. >        {
  21. >           p = CLine->data + Point;
  22. >           if (*p > ' ') break;
  23. >           del();
  24. >        }
  25.  
  26. >Here CLine->data is a pointer of same type as p and Point is an integer.
  27. >del() is a routine that has that might possibly do a realloc on
  28. >CLine->data so p might change in the loop.
  29.  
  30. >Would an optimizing compiler asssume that p will not change in the loop,
  31. >evaluate it once and assume it is fixed in the loop?  In this case, I would
  32. >want to declare it as volatile but I'd rather not worry about these issues.
  33. >Or should I?
  34.  
  35. Strangely enough, it depends on the compiler.  For example, Microsoft's
  36. C/C++ 7 gives one two options on this - /Oa to assume that there is no
  37. aliasing (function calls do not change variables) and /Ow for weak
  38. aliasing (function calls may change variables, but things in the code don't)
  39.  
  40. Hope this helps,
  41.  
  42. Steve.
  43.  
  44.