Path: utzoo!attcan!uunet!ncrlnk!ncr-sd!hp-sdd!hplabs!decwrl!purdue!haven!ncifcrf!nlm-mcs!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: const, volatile, etc [was Re: #defines with parameters] Message-ID: <9143@smoke.BRL.MIL> Date: 11 Dec 88 06:16:52 GMT References: <674@quintus.UUCP> <117@halcdc.UUCP> <468@auspex.UUCP> <9016@smoke.BRL.MIL> <10919@ulysses.homer.nj.att.com> <1450@micomvax.UUCP> <369@aber-cs.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 39 In article <369@aber-cs.UUCP> pcg@cs.aber.ac.uk (Piercarlo Grandi) writes: >They were not forbidden, you could do any optimization that did not impact >the semantics of programs. A Classic C program compiled with a dpANS C >compiler changes semantics, unless you tag with volatile all variables not >tagged register. This, as with practically everything else Grandi has said about C, is simply not true. There are a few fairly subtle changes in the semantics going from K&R 1st Ed. C to ANSI C, for example mixed type promotion in expressions and linkage rules, but they affect few programs. There was never a guarantee that C data had what is now known as the "volatile" property. Existing compilers in fact give the lie to such a claim. >Exactly the opposite! In Classic C the concept was that the compiler would >take register as an hint of which variables could always be safely cached in >register (and the user be forbidden to take pointer to them), and all the >others could be cached only if it was guaranteed that doing so would not >"cause surprises". Please cite references for this unique notion of what pre-ANSI C's rules were. So far as I have been able to determine, it was never specified one way or another, so by the usual rules for interpreting C rules, this would have been an unwise assumption to make. (Particularly since existing implementations did not follow that rule.) >Actually it is a backwards step wrt to register, as it encourages bloated >compilers and the delusion that they can select which variables to put in >registers better than you can do, while requiring careful analysis as to >which variables MUST be declared volatile (as failing to tag them makes >your program erroneous, where register is perfectly safe). "register" is still a supported specifier under ANSI C. Use it if you think your compiler does a poor job of register allocation. The use of "volatile" does not require much analysis. If you were paying attention, I already explained in response to Griff Smith the cases where you need to use it. In pre-ANSI C the same problem existed, but there was no standard solution for it.