Path: utzoo!utgpu!watmath!clyde!att!rutgers!mailrus!cornell!uw-beaver!microsoft!w-colinp From: w-colinp@microsoft.UUCP (Colin Plumb) Newsgroups: comp.lang.c Subject: Re: The world is not ready for 'volatile' Summary: An example of "register volatile" Message-ID: <184@microsoft.UUCP> Date: 5 Jan 89 01:01:03 GMT References: <141@bms-at.UUCP> <275@twwells.uucp> <15166@mimsy.UUCP> <9273@smoke.BRL.MIL> <15258@mimsy.UUCP> Reply-To: w-colinp@microsoft.UUCP (Colin Plumb) Organization: Microsoft Corp., Redmond WA Lines: 29 I can think of at least one example of a register volatile variable, if you're playing with setjmp/longjmp. We all know a non-volatile variable can't be trusted across a setjmp, so given register int x, y; jmp_buf jbuf; x = 0; y = setjmp(jbuf); x++; if (y = 0) longjmp(jbuf, 1); printf("x = %d\n", x); This "should" print 2, but a compiler could legitimately print x = 1. Obviously, x isn't aliased (register), and flow analysis (which isn't required to understand setjmp and longjmp) shows it is set to 0, incremented once, and printed. "Register volatile x" tells the compiler to try and store it somewhere quick, but safe from setjmp/longjmp. In most compilers, this would basically turn off the register declaration, but in transputer compilers I've used, "register" tells the compiler to keep the value in the 16 words nearest the stack pointer, which are especially quick to access. Here, register and volatile both mean something. Can anyone poke holes in this example? -- -Colin (uunet!microsof!w-colinp)