VHDL Issue Number: 1054 Classification: Language Definition Problem Language Version: VHDL-93 Summary: Short-circuit operators don't when called as functions Related Issues: Supersedes 0252 Relevant LRM Sections: 7.2, 7.2.1, 7.3.3 Key Words and Phrases: Short-circuit operators, expressions, function calls Current Status: ISAC-Approved 1076-1993 Disposition: N/A Disposition Rationale: N/A Superseded By: N/A ----------------------- Date Submitted: 1991/03/12 Author of Submission: Paul Menchini Author's Affiliation: Menchini & Associates Author's Post Address: 2 Davis Drive P.O. Box 13036 Research Triangle Park, NC 27709-3036 Author's Phone Number: 919.990.9506 Author's Fax Number: 919.990.9507 Author's Net Address: mench@mench.com ----------------------- Date Analyzed: 8 June 1995 Author of Analysis: John Willis (jwillis@acm.org) Revision Number: $Revision: 1.8 $ Date Last Revised: $Date: 1995/06/20 23:04:03 $ Description of Problem ---------------------- Consider the following two expressions: 1. a and b 2. "and" (a, b) These two expressions do not have identical semantics if the operator in expression 1 and the operator denoted by the prefix in expression 2 denote the same short-circuit operator. Specifically, in expression 1, if the value of a is sufficient to determine the entire expression's value, b is never evaluated. In contrast, in expression 2, b is always evaluated. The LRM is clear on this point. The first sentence of the last paragraph of Section 7.3.3 states (in part): Evaluation of a function call includes evaluation of the actual parameter expressions specified in the call .... No exception is made for function names that denote short-circuit operators. Proposed Resolution ------------------- Rework the language of the final paragraph of Section 7.3.3 to allow short- circuit operators called as functions to evaluate their second argument only as necessary to determine the value to be returned by the call. VASG-ISAC Analysis & Rationale ------------------------------ In Section 2.3.1 of the LRM, Note 2 speaks only of user-defined operators: "A user-defined operator that has the same designator as a short-circuit operator (this is, that overloads the short-circuit operator) is not invoked in a short-circuit manner. Specifically, calls to the user-defined operator always evaluate both arguments prior to the execution of the function". Thus user defined operators are never short circuited. Except for user-defined operators, Section 2.3.1, Note 2 appears to be completely consistent with the last paragraph of Section 7.3.3, which states: "Evaluation of a function call includes evaluation of the actual parameter expressions specified in the call and evaluation of the default expression expressions associated with the formal parameters of the function that do not have actual parameters associated with them." Note that LRM Section 2.3.1 Note 3 establishes the duality of operator and function call notations: "Functions that overload operator symbols may also be called using function call notation rather than operator notation. This is also true of the predefined operators themselves". For example: variable a, b: bit; a and b is just another notation for "and" (a, b) However according to the LRM, the two notations have distinct semantics (one call is short-circuit, one is not). Having distinct semantics for predefined operator (short circuited) and function call notation (never short circuited) is well-defined by the '93 LRM however this seems like a distinction which violates the duality which Section 2.3.1 Note 3 tries to establish. VASG-ISAC Recommendation for IEEE Std 1076-1993 ----------------------------------------------- In order to maintain the duality of operator and function call notations for predefined operators, LRM Section 7.3.3 should be modified as follows: "Function calls which denote a predefined, short-circuit operator must be converted into the equivalent operator form before evaluation. Evaluation of remaining function calls includes both an evaluation of the actual parameter expressions specified in the call and evaluation of the default expressions associated with formal parameters of the function call which do not have actual parameters associated with them. In both cases ... " Note addition of the first sentance clarifying treatment of calls to predefined, short-circuit operators and exclusion of such calls from the second (originally first) sentance.