home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!baillie
- From: baillie@cs.mu.OZ.AU (Stephen Baillie)
- Subject: Re: Paranoia, side effects, and optimizing compilers
- Message-ID: <9222819.26380@mulga.cs.mu.OZ.AU>
- Organization: Computer Science, University of Melbourne, Australia
- References: <DAVIS.92Aug14120003@pacific.mps.ohio-state.edu>
- Date: Sat, 15 Aug 1992 09:26:54 GMT
- Lines: 33
-
- davis@pacific.mps.ohio-state.edu ("John E. Davis") writes:
-
- >Hi,
-
- > Consider:
-
- > unsigned char *p;
- >
- > while (1)
- > {
- > p = CLine->data + Point;
- > if (*p > ' ') break;
- > del();
- > }
-
- >Here CLine->data is a pointer of same type as p and Point is an integer.
- >del() is a routine that has that might possibly do a realloc on
- >CLine->data so p might change in the loop.
-
- >Would an optimizing compiler asssume that p will not change in the loop,
- >evaluate it once and assume it is fixed in the loop? In this case, I would
- >want to declare it as volatile but I'd rather not worry about these issues.
- >Or should I?
-
- Strangely enough, it depends on the compiler. For example, Microsoft's
- C/C++ 7 gives one two options on this - /Oa to assume that there is no
- aliasing (function calls do not change variables) and /Ow for weak
- aliasing (function calls may change variables, but things in the code don't)
-
- Hope this helps,
-
- Steve.
-
-