From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: Date: Thu, 8 Dec 2005 21:04:51 -0500 From: Russ Cox To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu> Subject: Re: [9fans] const In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <2dcfe3e91404eb3e8623378927444467@coraid.com> Topicbox-Message-UUID: bf98063c-ead0-11e9-9d60-3106f5b1d025 > At a quick read, it appears that `const' and `volatile' are treated as > `garbage type qualifiers' and ignored. Const is ignored. Volatile is not ignored anymore. /sys/src/cmd/cc/dcl.c:768 or so inserts USED(&x) if you declare volatile int x;, presumably so that the compiler will not registerize x. This is occasionally necessary in the kernel because of waserror(). For example: x =3D 0; if(waserror()){ print("x=3D%d\n", x); nexterror(); } x =3D 1; x =3D f(x); If f errors, then the waserror might print 0 if the compiler has chosen not to store the 1 (it's not used after the call to f -- it will be overwritten once f returns). This happens in namec in /sys/src/9/port/chan.c. Rob defined an empty function saveregisters() and called it to force the compiler to write the new value of x to memory before calling f (in this case, devtab[c->type]->open). It could be replaced by making c volatile now, though I'd rather not. Russ