1 --- ./gcc/doc/extend.texi.orig Sat Aug 6 15:26:27 2005
2 +++ ./gcc/doc/extend.texi Mon Aug 22 00:14:05 2005
4 * Pragmas:: Pragmas accepted by GCC.
5 * Unnamed Fields:: Unnamed struct/union fields within structs/unions.
6 * Thread-Local:: Per-thread variables.
7 +* Binary constants:: Binary constants using the @samp{0b} prefix.
11 @@ -9742,6 +9743,28 @@
12 Non-@code{static} members shall not be @code{__thread}.
16 +@node Binary constants
17 +@section Binary constants using the @samp{0b} prefix
18 +@cindex Binary constants using the @samp{0b} prefix
20 +Integer constants can be written as binary constants, consisting of a
21 +sequence of @samp{0} and @samp{1} digits, prefixed by @samp{0b} or
22 +@samp{0B}. This is particularly useful in environments that operate a
23 +lot on the bit-level (like microcontrollers).
25 +The following statements are identical:
34 +The type of these constants follows the same rules as for octal or
35 +hexadecimal integer constants, so suffixes like @samp{L} or @samp{UL}
39 @chapter Extensions to the C++ Language
40 --- ./libcpp/include/cpplib.h.orig Wed Jun 29 04:34:39 2005
41 +++ ./libcpp/include/cpplib.h Mon Aug 22 00:14:05 2005
43 #define CPP_N_DECIMAL 0x0100
44 #define CPP_N_HEX 0x0200
45 #define CPP_N_OCTAL 0x0400
46 +#define CPP_N_BINARY 0x0800
48 #define CPP_N_UNSIGNED 0x1000 /* Properties. */
49 #define CPP_N_IMAGINARY 0x2000
50 --- ./libcpp/expr.c.orig Wed Jun 29 04:34:36 2005
51 +++ ./libcpp/expr.c Mon Aug 22 12:02:28 2005
56 + else if ((*str == 'b' || *str == 'B') && (str[1] == '0' || str[1] == '1'))
63 /* Now scan for a well-formed integer or float. */
67 if (max_digit >= radix)
68 - SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
71 + SYNTAX_ERROR2 ("invalid digit \"%c\" in binary constant", '0' + max_digit);
73 + SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
76 if (float_flag != NOT_FLOAT)
80 + cpp_error (pfile, CPP_DL_ERROR,
81 + "invalid prefix \"0b\" for floating constant");
82 + return CPP_N_INVALID;
85 if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
86 cpp_error (pfile, CPP_DL_PEDWARN,
87 "use of C99 hexadecimal floating constant");
89 if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
90 cpp_error (pfile, CPP_DL_PEDWARN,
91 "imaginary constants are a GCC extension");
92 + if (radix == 2 && CPP_PEDANTIC (pfile))
93 + cpp_error (pfile, CPP_DL_PEDWARN,
94 + "binary constants are a GCC extension");
97 result |= CPP_N_DECIMAL;
100 + else if (radix == 2)
101 + result |= CPP_N_BINARY;
103 result |= CPP_N_OCTAL;
109 + else if ((type & CPP_N_RADIX) == CPP_N_BINARY)
115 /* We can add a digit to numbers strictly less than this without
116 needing the precision and slowness of double integers. */
117 @@ -398,12 +425,25 @@
118 append_digit (cpp_num num, int digit, int base, size_t precision)
121 - unsigned int shift = 3 + (base == 16);
122 + unsigned int shift;
124 cpp_num_part add_high, add_low;
126 - /* Multiply by 8 or 16. Catching this overflow here means we don't
127 + /* Multiply by 2, 8 or 16. Catching this overflow here means we don't
128 need to worry about add_high overflowing. */
142 overflow = !!(num.high >> (PART_PRECISION - shift));
143 result.high = num.high << shift;
144 result.low = num.low << shift;