J3/99-261 Date: 30 Nov 1999 From: Dick Hendrickson Subject: Simpler Example of Volatile References: 99-252, issue 34 [438], issue 83 [7] Replace section C.2.3 with a simpler example of use of the VOLATILE attribute. This will eliminate the need for Copyright notices and be easier to follow. Also add a reference to the C standard in chapter one. Edites: Replace page 438, lines 21-53 and page 439 lines 1-49 with: The following example shows the use of a variable with the VOLATILE attribute to communicate with an asynchronous process, in this case the operating system. The program detects a user keystroke on the terminal and reacts at a convenient point in its processing. The VOLATILE attribute is necessary to prevent an optimizing compiler from storing the communication variable in a register or from doing flow analysis and deciding that the EXIT statement can never be executed. Subroutine Terminate_Iterations Logical, VOLATILE :: user_hit_any_key ... ! have the OS start to look for a user keystroke and set the variable "user_hit_any_key" ! to TRUE when it detects a keystroke Call operating_system("BEGIN DETECT USER KEYSTROKE", user_hit_any_key) user_hit_any_key = .false. !this will ignore any recent keystrokes print *, "hit any key to terminate iterations!" Do I = 1,100 ..... ! compute a value for R print *, I, R if (user_hit_any_key) EXIT Enddo !Have the OS stop looking for user keystrokes Call operating_system("STOP DETECT USER KEYSTROKE") End Subroutine Terminate_Iterations Page 7, line 6, Add ISO/IEC 9899-1990 Information Technology - Programming Languages - C We refer to this standard as the C standard. Page 7, lines 7-11, change the text of note 83 to When the forthcoming standard revision of the C standard has been published, the reference to ISO/IEC 9899-1990 should be updated.