J3/04-127 Date: 13 Dec. 2003 To: J3 From: Dan Nagle Subject: VOLATILE Functions For some time now, there has been an ongoing debate over the exact circumstances where a programmer is guaranteed that a function in an expression must be executed. There are, however, some advantages to the current ambiguity, to wit: the freedom given optimizers to generate faster code. Some papers have been written suggesting new language to remove said ambiguities. This paper proposes another approach, specifically, the VOLATILE attribute for functions. This was considered for Fortran 2003 at the last minute, but was viewed as too extensive to be incorporated at that time. Interoperability with C, where function side-effects are common, and the language definition gives the explicit requirement that all function references must result in function execution, only exacerbates the problem. Number: Title: VOLATILE Functions Submitted By: J3 Status: For Consideration References: J3/03-163 Basic Functionality: A VOLATILE function must be executed, whether the expression containing the reference requires the function value for computation of the value of the expression, or not. Rationale: The current language is ambiguous, yet the ambiguity serves a purpose well. Following the example set by SAVE and (the future) AUTOMATIC attributes for variables, and in parallel with the meaning of VOLATILE for variables, the proposal is to create the VOLATILE attribute for functions. That is, defer the issue to the programmer, who may indicate that a function is PURE or VOLATILE. Functions with neither attribute may be treated by compilers in a processor dependent way. Estimated Impact: Compilers will have to recognize the keyword in a new situation, and support a new attribute for functions. The handling of expressions is affected. For this price, programmers are given full control of whether a function reference may be elided. Detailed Specification: J3/03-163 contains the specification. I will not attempt to improve upon it, as this paper requests reconsideration of 03-163 in the next standard. History: