X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=blobdiff_plain;f=doc%2Fspecification.tex;h=74190fc4aa766cd838bcebe51797a1cd6670f07d;hp=2687946f1da77fe0e1572fe2d042e95f86f0b3f7;hb=a68f0fcb355db42acabe72da5939fbd1b04f6016;hpb=bedfee1fae30e47e13013d197b69e15534767b05 diff --git a/doc/specification.tex b/doc/specification.tex index 2687946..74190fc 100644 --- a/doc/specification.tex +++ b/doc/specification.tex @@ -363,17 +363,17 @@ types, as follows: \begin{itemize} \item An array type describes a contiguously allocated nonempty set of objects with a - particular object type, called the element type. Array types are characterized - by their element type and by the number of elements in the array. An array type - is said to be derived from its element type, and if its element is type T, the - array type is sometimes called "array of T". The construction of an array type - from an element type is called "array type derivation". + particular object type, called the element type. Array types are characterized + by their element type and by the number of elements in the array. An array type + is said to be derived from its element type, and if its element is type T, the + array type is sometimes called "array of T". The construction of an array type + from an element type is called "array type derivation". \item A function type describes a function with a specified return type. A function - type is characterized by its return type and the number and types of its - parameters. A function type is said to be derived from its return type, and if - its return type is T, the function type is sometimes called "function returning - T". The construction of a function type from a return type is called "function - type derivation". + type is characterized by its return type and the number and types of its + parameters. A function type is said to be derived from its return type, and if + its return type is T, the function type is sometimes called "function returning + T". The construction of a function type from a return type is called "function + type derivation". \end{itemize} Arithmetic types are collectively called scalar types. Arrays and vectors are @@ -707,6 +707,52 @@ those of the unparenthesized expression. It is an lvalue, a function designator void expression if the unparenthesized expression is, respectively, an lvalue, a function designator, or a void expression. +%% ->-> Constant expressions %% +\subsubsection{Constant expressions} +\paragraph*{Syntax} +\begin{lstlisting}[language=bnf] +constant-expression ::= conditional-expression +\end{lstlisting} +\paragraph*{Description} +A constant expression can be evaluated during translation rather than runtime, and +accordingly may be used in any place that a constant may be. +\paragraph*{Constraints} +\begin{itemize} + \item Constant expressions shall not contain assignment, increment, decrement, + function-call, or comma operators, except when contained within a subexpression + that is not evaluated. + \item Each constant expression shall evaluate to a constant that is in range of + representable values for its type. +\end{itemize} +\paragraph*{Semantics} +An expression that evaluates to a constant is required in several contexts. If a floating +point expression is evaluated in the translation environment, the arithmetic precision range +shall be as great is if the expression were being evaluated in the execution environment. +\linebreak + +An integer constant expression shall have integer type and shall only have operands that +are integer constants, enumeration constants, character constants, and floating constants +that are the immediate operand of casts. Cast operators in an integer constant expression +shall only convert arithmetic types to integer types. +\linebreak + +More latitude is permitted for constant expressions in initializers. Such a constant expression +shall be, or evaluate to an arithmetic constant expression. +\linebreak + +An arithmetic constant expression shall have arithmetic type and shall only have operands that +are integer constants, floating constants, enumeration constants, and character constants. Cast +operators in an arithmetic constant expression shall only convert arithmetic types to arithmetic +types. +\linebreak + +An implementation may accept other forms of constant expressions. +\linebreak + +The semantic rules for the evaluation of a constant expression are the same as for nonconstant +expressions. + + \bibliographystyle{abbrv} \bibliography{main}