|
397 | 397 | \pnum |
398 | 398 | \begin{example} |
399 | 399 | The program fragment \tcode{0xe+foo} is parsed as a |
400 | | -preprocessing number token (one that is not a valid integer or floating-point |
401 | | -literal token), even though a parse as three preprocessing tokens |
| 400 | +preprocessing number token (one that is not a valid |
| 401 | +\grammarterm{integer-literal} or \grammarterm{floating-point-literal} token), |
| 402 | +even though a parse as three preprocessing tokens |
402 | 403 | \tcode{0xe}, \tcode{+}, and \tcode{foo} might produce a valid expression (for example, |
403 | 404 | if \tcode{foo} were a macro defined as \tcode{1}). Similarly, the |
404 | 405 | program fragment \tcode{1E1} is parsed as a preprocessing number (one |
405 | | -that is a valid floating-point literal token), whether or not \tcode{E} is a |
406 | | -macro name. |
| 406 | +that is a valid \grammarterm{floating-point-literal} token), |
| 407 | +whether or not \tcode{E} is a macro name. |
407 | 408 | \end{example} |
408 | 409 |
|
409 | 410 | \pnum |
|
583 | 584 | \end{bnf} |
584 | 585 |
|
585 | 586 | \pnum |
586 | | -Preprocessing number tokens lexically include all integer literal |
587 | | -tokens\iref{lex.icon} and all floating-point literal |
588 | | -tokens\iref{lex.fcon}. |
| 587 | +Preprocessing number tokens lexically include |
| 588 | +all \grammarterm{integer-literal} tokens\iref{lex.icon} and |
| 589 | +all \grammarterm{floating-point-literal} tokens\iref{lex.fcon}. |
589 | 590 |
|
590 | 591 | \pnum |
591 | 592 | A preprocessing number does not have a type or a value; it acquires both |
592 | | -after a successful conversion to an integer literal token or a floating-point literal |
593 | | -token.% |
| 593 | +after a successful conversion to |
| 594 | +an \grammarterm{integer-literal} token or |
| 595 | +a \grammarterm{floating-point-literal} token.% |
594 | 596 | \indextext{number!preprocessing|)} |
595 | 597 |
|
596 | 598 | \rSec1[lex.name]{Identifiers} |
|
1033 | 1035 | \indextext{literal!\idxcode{unsigned}}% |
1034 | 1036 | \indextext{literal!\idxcode{long}}% |
1035 | 1037 | \indextext{literal!base of integer}% |
1036 | | -An \defnx{integer literal}{literal!integer} is a sequence of digits that has no period |
1037 | | -or exponent part, with optional separating single quotes that are ignored |
1038 | | -when determining its value. An integer literal may have a prefix that specifies |
1039 | | -its base and a suffix that specifies its type. The lexically first digit |
1040 | | -of the sequence of digits is the most significant. |
1041 | | -A \defnx{binary integer literal}{literal!binary} (base two) begins with |
1042 | | -\tcode{0b} or \tcode{0B} and consists of a sequence of binary digits. |
1043 | | -An \defnx{octal integer literal}{literal!octal} |
1044 | | -(base eight) begins with the digit \tcode{0} and consists of a |
1045 | | -sequence of octal digits.\footnote{The digits \tcode{8} and \tcode{9} are not octal digits. } |
1046 | | -A \defnx{decimal integer literal}{literal!decimal} |
1047 | | -(base ten) begins with a digit other than \tcode{0} and |
1048 | | -consists of a sequence of decimal digits. |
1049 | | -A \defnx{hexadecimal integer literal}{literal!hexadecimal} |
1050 | | -(base sixteen) begins with |
1051 | | -\tcode{0x} or \tcode{0X} and consists of a sequence of hexadecimal |
1052 | | -digits, which include the decimal digits and the letters \tcode{a} |
1053 | | -through \tcode{f} and \tcode{A} through \tcode{F} with decimal values |
1054 | | -ten through fifteen. |
| 1038 | +In an \grammarterm{integer-literal}, |
| 1039 | +the sequence of |
| 1040 | +\grammarterm{binary-digit}s, |
| 1041 | +\grammarterm{octal-digit}s, |
| 1042 | +\grammarterm{digit}s, or |
| 1043 | +\grammarterm{hexadecimal-digit}s |
| 1044 | +is interpreted as a base $N$ integer as shown in table \tref{lex.icon.base}; |
| 1045 | +the lexically first digit of the sequence of digits is the most significant. |
| 1046 | +\begin{note} |
| 1047 | +The prefix and any optional separating single quotes are ignored |
| 1048 | +when determining the value. |
| 1049 | +\end{note} |
| 1050 | + |
| 1051 | +\begin{simpletypetable} |
| 1052 | +{Base of \grammarterm{integer-literal}{s}} |
| 1053 | +{lex.icon.base} |
| 1054 | +{lr} |
| 1055 | +\topline |
| 1056 | +\lhdr{Kind of \grammarterm{integer-literal}} & \rhdr{base $N$} \\ \capsep |
| 1057 | +\grammarterm{binary-literal} & 2 \\ |
| 1058 | +\grammarterm{octal-literal} & 8 \\ |
| 1059 | +\grammarterm{decimal-literal} & 10 \\ |
| 1060 | +\grammarterm{hexadecimal-literal} & 16 \\ |
| 1061 | +\end{simpletypetable} |
| 1062 | + |
| 1063 | +\pnum |
| 1064 | +The \grammarterm{hexadecimal-digit}s |
| 1065 | +\tcode{a} through \tcode{f} and \tcode{A} through \tcode{F} |
| 1066 | +have decimal values ten through fifteen. |
1055 | 1067 | \begin{example} |
1056 | 1068 | The number twelve can be written \tcode{12}, \tcode{014}, |
1057 | | -\tcode{0XC}, or \tcode{0b1100}. The integer literals \tcode{1048576}, |
| 1069 | +\tcode{0XC}, or \tcode{0b1100}. The \grammarterm{integer-literal}s \tcode{1048576}, |
1058 | 1070 | \tcode{1'048'576}, \tcode{0X100000}, \tcode{0x10'0000}, and |
1059 | 1071 | \tcode{0'004'000'000} all have the same value. |
1060 | 1072 | \end{example} |
|
1068 | 1080 | \indextext{suffix!\idxcode{U}}% |
1069 | 1081 | \indextext{suffix!\idxcode{l}}% |
1070 | 1082 | \indextext{suffix!\idxcode{u}}% |
1071 | | -The type of an integer literal is the first of the corresponding list |
1072 | | -in \tref{lex.icon.type} in which its value can be |
1073 | | -represented. |
| 1083 | +The type of an \grammarterm{integer-literal} is |
| 1084 | +the first type in the list in \tref{lex.icon.type} |
| 1085 | +corresponding to its optional \grammarterm{integer-suffix} |
| 1086 | +in which its value can be represented. |
| 1087 | +An \grammarterm{integer-literal} is a prvalue. |
1074 | 1088 |
|
1075 | | -\enlargethispage{\baselineskip}% |
1076 | | -\begin{LongTable}{Types of integer literals}{lex.icon.type}{l|l|l} |
| 1089 | +\begin{LongTable}{Types of \grammarterm{integer-literal}s}{lex.icon.type}{l|l|l} |
1077 | 1090 | \\ \topline |
1078 | | -\lhdr{Suffix} & \chdr{Decimal literal} & \rhdr{Binary, octal, or hexadecimal literal} \\ \capsep |
| 1091 | +\lhdr{\grammarterm{integer-suffix}} & \chdr{\grammarterm{decimal-literal}} & \rhdr{\grammarterm{integer-literal} other than \grammarterm{decimal-literal}} \\ \capsep |
1079 | 1092 | \endfirsthead |
1080 | 1093 | \continuedcaption\\ |
1081 | 1094 | \hline |
1082 | | -\lhdr{Suffix} & \chdr{Decimal literal} & \rhdr{Binary, octal, or hexadecimal literal} \\ \capsep |
| 1095 | +\lhdr{\grammarterm{integer-suffix}} & \chdr{\grammarterm{decimal-literal}} & \rhdr{\grammarterm{integer-literal} other than \grammarterm{decimal-literal}} \\ \capsep |
1083 | 1096 | \endhead |
1084 | 1097 | none & |
1085 | 1098 | \tcode{int} & |
|
1141 | 1154 | \end{LongTable} |
1142 | 1155 |
|
1143 | 1156 | \pnum |
1144 | | -If an integer literal cannot be represented by any type in its list and |
1145 | | -an extended integer type\iref{basic.fundamental} can represent its value, it may have that |
1146 | | -extended integer type. If all of the types in the list for the integer literal |
1147 | | -are signed, the extended integer type shall be signed. If all of the |
1148 | | -types in the list for the integer literal are unsigned, the extended integer |
1149 | | -type shall be unsigned. If the list contains both signed and unsigned |
1150 | | -types, the extended integer type may be signed or unsigned. A program is |
1151 | | -ill-formed if one of its translation units contains an integer literal |
| 1157 | +If an \grammarterm{integer-literal} |
| 1158 | +cannot be represented by any type in its list and |
| 1159 | +an extended integer type\iref{basic.fundamental} can represent its value, |
| 1160 | +it may have that extended integer type. |
| 1161 | +If all of the types in the list for the \grammarterm{integer-literal} |
| 1162 | +are signed, |
| 1163 | +the extended integer type shall be signed. |
| 1164 | +If all of the types in the list for the \grammarterm{integer-literal} |
| 1165 | +are unsigned, |
| 1166 | +the extended integer type shall be unsigned. |
| 1167 | +If the list contains both signed and unsigned types, |
| 1168 | +the extended integer type may be signed or unsigned. |
| 1169 | +A program is ill-formed |
| 1170 | +if one of its translation units contains an \grammarterm{integer-literal} |
1152 | 1171 | that cannot be represented by any of the allowed types. |
1153 | 1172 |
|
1154 | 1173 | \rSec2[lex.ccon]{Character literals} |
|
1454 | 1473 | \end{bnf} |
1455 | 1474 |
|
1456 | 1475 | \pnum |
1457 | | -\indextext{literal!floating-point}% |
1458 | | -A floating-point literal consists of |
1459 | | -an optional prefix specifying a base, |
1460 | | -an integer part, |
1461 | | -a radix point, |
1462 | | -a fraction part, |
1463 | | -\indextext{suffix!\idxcode{e}}% |
1464 | | -\indextext{suffix!\idxcode{E}}% |
1465 | | -\indextext{suffix!\idxcode{p}}% |
1466 | | -\indextext{suffix!\idxcode{P}}% |
1467 | | -an \tcode{e}, \tcode{E}, \tcode{p} or \tcode{P}, |
1468 | | -an optionally signed integer exponent, and |
1469 | | -an optional type suffix. |
1470 | | -The integer and fraction parts both consist of |
1471 | | -a sequence of decimal (base ten) digits if there is no prefix, or |
1472 | | -hexadecimal (base sixteen) digits if the prefix is \tcode{0x} or \tcode{0X}. |
1473 | | -The floating-point literal is a \defnadj{decimal floating-point}{literal} in the former case and |
1474 | | -a \defnadj{hexadecimal floating}{literal} in the latter case. |
1475 | | -Optional separating single quotes in |
1476 | | -a \grammarterm{digit-sequence} or \grammarterm{hexadecimal-digit-sequence} |
1477 | | -are ignored when determining its value. |
1478 | | -\begin{example} |
1479 | | -The floating-point literals \tcode{1.602'176'565e-19} and \tcode{1.602176565e-19} |
1480 | | -have the same value. |
1481 | | -\end{example} |
1482 | | -Either the integer part or the fraction part (not both) can be omitted. |
1483 | | -Either the radix point or the letter \tcode{e} or \tcode{E} and |
1484 | | -the exponent (not both) can be omitted from a decimal floating-point literal. |
1485 | | -The radix point (but not the exponent) can be omitted |
1486 | | -from a hexadecimal floating-point literal. |
1487 | | -The integer part, the optional radix point, and the optional fraction part, |
1488 | | -form the \defn{significand} of the floating-point literal. |
1489 | | -In a decimal floating-point literal, the exponent, if present, |
1490 | | -indicates the power of 10 by which the significand is to be scaled. |
1491 | | -In a hexadecimal floating-point literal, the exponent |
1492 | | -indicates the power of 2 by which the significand is to be scaled. |
1493 | | -\begin{example} |
1494 | | -The floating-point literals \tcode{49.625} and \tcode{0xC.68p+2} have the same value. |
1495 | | -\end{example} |
1496 | | -If the scaled value is in |
1497 | | -the range of representable values for its type, the result is the scaled |
1498 | | -value if representable, else the larger or smaller representable value |
1499 | | -nearest the scaled value, chosen in an \impldef{choice of larger or smaller value of |
1500 | | -floating-point literal} manner. |
1501 | | -\indextext{literal!\idxcode{double}}% |
1502 | | -The type of a floating-point literal is \tcode{double} |
1503 | 1476 | \indextext{literal!type of floating-point}% |
1504 | | -unless explicitly specified by a suffix. |
1505 | 1477 | \indextext{literal!\idxcode{float}}% |
1506 | 1478 | \indextext{suffix!\idxcode{F}}% |
1507 | 1479 | \indextext{suffix!\idxcode{f}}% |
1508 | | -The suffixes \tcode{f} and \tcode{F} specify \tcode{float}, |
1509 | 1480 | \indextext{suffix!\idxcode{L}}% |
1510 | 1481 | \indextext{suffix!\idxcode{l}}% |
1511 | 1482 | \indextext{literal!\idxcode{long double}}% |
1512 | | -the suffixes \tcode{l} and \tcode{L} specify \tcode{long} |
1513 | | -\tcode{double}. If the scaled value is not in the range of representable |
| 1483 | +The type of a \grammarterm{floating-point-literal} is determined by |
| 1484 | +its \grammarterm{floating-point-suffix} as specified in \tref{lex.fcon.type}. |
| 1485 | +\begin{simpletypetable} |
| 1486 | +{Types of \grammarterm{floating-point-literal}{s}} |
| 1487 | +{lex.fcon.type} |
| 1488 | +{ll} |
| 1489 | +\topline |
| 1490 | +\lhdr{\grammarterm{floating-point-suffix}} & \rhdr{type} \\ \capsep |
| 1491 | +none & \keyword{double} \\ |
| 1492 | +\tcode{f} or \tcode{F} & \keyword {float} \\ |
| 1493 | +\tcode{l} or \tcode{L} & \keyword{long} \keyword{double} \\ |
| 1494 | +\end{simpletypetable} |
| 1495 | + |
| 1496 | +\pnum |
| 1497 | +\indextext{literal!floating-point}% |
| 1498 | +The \defn{significand} of a \grammarterm{floating-point-literal} |
| 1499 | +is the \grammarterm{fractional-constant} or \grammarterm{digit-sequence} |
| 1500 | +of a \grammarterm{decimal-floating-point-literal} |
| 1501 | +or the \grammarterm{hexadecimal-fractional-constant} |
| 1502 | +or \grammarterm{hexadecimal-digit-sequence} |
| 1503 | +of a \grammarterm{hexadecimal-floating-point-literal}. |
| 1504 | +In the significand, |
| 1505 | +the sequence of \grammarterm{digit}s or \grammarterm{hexadecimal-digit}s |
| 1506 | +and optional period are interpreted as a base $N$ real number $s$, |
| 1507 | +where $N$ is 10 for a \grammarterm{decimal-floating-point-literal} and |
| 1508 | +16 for a \grammarterm{hexadecimal-floating-point-literal}. |
| 1509 | +\begin{note} |
| 1510 | +Any optional separating single quotes are ignored when determining the value. |
| 1511 | +\end{note} |
| 1512 | +If an \grammarterm{exponent-part} or \grammarterm{binary-exponent-part} |
| 1513 | +is present, |
| 1514 | +the exponent $e$ of the \grammarterm{floating-point-literal} |
| 1515 | +is the result of interpreting |
| 1516 | +the sequence of an optional \grammarterm{sign} and the \grammarterm{digit}s |
| 1517 | +as a base 10 integer. |
| 1518 | +Otherwise, the exponent $e$ is 0. |
| 1519 | +The scaled value of the literal is |
| 1520 | +$s \times 10^e$ for a \grammarterm{decimal-floating-point-literal} and |
| 1521 | +$s \times 2^e$ for a \grammarterm{hexadecimal-floating-point-literal}. |
| 1522 | +\begin{example} |
| 1523 | +The \grammarterm{floating-point-literal}{s} |
| 1524 | +\tcode{49.625} and \tcode{0xC.68p+2} have the same value. |
| 1525 | +The \grammarterm{floating-point-literal}{s} |
| 1526 | +\tcode{1.602'176'565e-19} and \tcode{1.602176565e-19} |
| 1527 | +have the same value. |
| 1528 | +\end{example} |
| 1529 | + |
| 1530 | +\pnum |
| 1531 | +If the scaled value is not in the range of representable |
1514 | 1532 | values for its type, the program is ill-formed. |
| 1533 | +Otherwise, the value of a \grammarterm{floating-point-literal} |
| 1534 | +is the scaled value if representable, |
| 1535 | +else the larger or smaller representable value nearest the scaled value, |
| 1536 | +chosen in an \impldef{choice of larger or smaller value of |
| 1537 | +\grammarterm{floating-point-literal}} manner. |
1515 | 1538 |
|
1516 | 1539 | \rSec2[lex.string]{String literals} |
1517 | 1540 |
|
|
0 commit comments