View | Details | Return to bug 23479 | Differences between
and this patch

Collapse All | Expand All

(-)gcc/doc/extend.texi (+23 lines)
Lines 81-86 Link Here
81
* Pragmas::             Pragmas accepted by GCC.
81
* Pragmas::             Pragmas accepted by GCC.
82
* Unnamed Fields::      Unnamed struct/union fields within structs/unions.
82
* Unnamed Fields::      Unnamed struct/union fields within structs/unions.
83
* Thread-Local::        Per-thread variables.
83
* Thread-Local::        Per-thread variables.
84
* Binary constants::    Binary constants using the @samp{0b} prefix.
84
@end menu
85
@end menu
85
86
86
@node Statement Exprs
87
@node Statement Exprs
Lines 10495-10500 Link Here
10495
@end quotation
10496
@end quotation
10496
@end itemize
10497
@end itemize
10497
10498
10499
@node Binary constants
10500
@section Binary constants using the @samp{0b} prefix
10501
@cindex Binary constants using the @samp{0b} prefix
10502
10503
Integer constants can be written as binary constants, consisting of a
10504
sequence of @samp{0} and @samp{1} digits, prefixed by @samp{0b} or
10505
@samp{0B}.  This is particularly useful in environments that operate a
10506
lot on the bit-level (like microcontrollers).
10507
10508
The following statements are identical:
10509
10510
@smallexample
10511
i =       42;
10512
i =     0x2a;
10513
i =      052;
10514
i = 0b101010;
10515
@end smallexample
10516
10517
The type of these constants follows the same rules as for octal or
10518
hexadecimal integer constants, so suffixes like @samp{L} or @samp{UL}
10519
can be applied.
10520
10498
@node C++ Extensions
10521
@node C++ Extensions
10499
@chapter Extensions to the C++ Language
10522
@chapter Extensions to the C++ Language
10500
@cindex extensions, C++ language
10523
@cindex extensions, C++ language
(-)gcc/testsuite/gcc.dg/binary-constants-1.c (+312 lines)
Line 0 Link Here
1
/* Test for binary integer constants.  */
2
3
/* Derived from: c99-intconst-1.c, bye Joseph Myers <jsm28@cam.ac.uk>.  */
4
/* Origin: Joerg Wunsch <j.gnu@uriah.heep.sax.de>.  */
5
/* { dg-do compile } */
6
/* { dg-options "-std=gnu99" } */
7
8
#include <limits.h>
9
10
/* Assertion that constant C is of type T.  */
11
#define ASSERT_CONST_TYPE(C, T)			\
12
	do {					\
13
	  typedef T type;			\
14
	  typedef type **typepp;		\
15
	  typedef __typeof__((C)) ctype;	\
16
	  typedef ctype **ctypepp;		\
17
	  typepp x = 0;				\
18
	  ctypepp y = 0;			\
19
	  x = y;				\
20
	  y = x;				\
21
	} while (0)
22
23
/* (T *) if E is zero, (void *) otherwise.  */
24
#define type_if_not(T, E) __typeof__(0 ? (T *)0 : (void *)(E))
25
26
/* (T *) if E is nonzero, (void *) otherwise.  */
27
#define type_if(T, E) type_if_not(T, !(E))
28
29
/* Combine pointer types, all but one (void *).  */
30
#define type_comb2(T1, T2) __typeof__(0 ? (T1)0 : (T2)0)
31
#define type_comb3(T1, T2, T3) type_comb2(T1, type_comb2(T2, T3))
32
#define type_comb4(T1, T2, T3, T4)				\
33
	type_comb2(T1, type_comb2(T2, type_comb2(T3, T4)))
34
#define type_comb6(T1, T2, T3, T4, T5, T6)				   \
35
	type_comb2(T1,							   \
36
		   type_comb2(T2,					   \
37
			      type_comb2(T3,				   \
38
					 type_comb2(T4,			   \
39
						    type_comb2(T5, T6)))))
40
41
/* (T1 *) if E1, otherwise (T2 *) if E2.  */
42
#define first_of2p(T1, E1, T2, E2) type_comb2(type_if(T1, (E1)),	   \
43
					     type_if(T2, (!(E1) && (E2))))
44
/* (T1 *) if E1, otherwise (T2 *) if E2, otherwise (T3 *) if E3.  */
45
#define first_of3p(T1, E1, T2, E2, T3, E3)			\
46
	type_comb3(type_if(T1, (E1)),				\
47
		   type_if(T2, (!(E1) && (E2))),		\
48
		   type_if(T3, (!(E1) && !(E2) && (E3))))
49
/* (T1 *) if E1, otherwise (T2 *) if E2, otherwise (T3 *) if E3, otherwise
50
   (T4 *) if E4.  */
51
#define first_of4p(T1, E1, T2, E2, T3, E3, T4, E4)			\
52
	type_comb4(type_if(T1, (E1)),					\
53
		   type_if(T2, (!(E1) && (E2))),			\
54
		   type_if(T3, (!(E1) && !(E2) && (E3))),		\
55
		   type_if(T4, (!(E1) && !(E2) && !(E3) && (E4))))
56
/* (T1 *) if E1, otherwise (T2 *) if E2, otherwise (T3 *) if E3, otherwise
57
   (T4 *) if E4, otherwise (T5 *) if E5, otherwise (T6 *) if E6.  */
58
#define first_of6p(T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6)	    \
59
	type_comb6(type_if(T1, (E1)),					    \
60
		   type_if(T2, (!(E1) && (E2))),			    \
61
		   type_if(T3, (!(E1) && !(E2) && (E3))),		    \
62
		   type_if(T4, (!(E1) && !(E2) && !(E3) && (E4))),	    \
63
		   type_if(T5, (!(E1) && !(E2) && !(E3) && !(E4) && (E5))), \
64
		   type_if(T6, (!(E1) && !(E2) && !(E3)			    \
65
				&& !(E4) && !(E5) && (E6))))
66
67
/* Likewise, but return the original type rather than a pointer type.  */
68
#define first_of2(T1, E1, T2, E2)			\
69
	__typeof__(*((first_of2p(T1, (E1), T2, (E2)))0))
70
#define first_of3(T1, E1, T2, E2, T3, E3)				\
71
	__typeof__(*((first_of3p(T1, (E1), T2, (E2), T3, (E3)))0))
72
#define first_of4(T1, E1, T2, E2, T3, E3, T4, E4)			    \
73
	__typeof__(*((first_of4p(T1, (E1), T2, (E2), T3, (E3), T4, (E4)))0))
74
#define first_of6(T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6)	\
75
	__typeof__(*((first_of6p(T1, (E1), T2, (E2), T3, (E3),		\
76
				 T4, (E4), T5, (E5), T6, (E6)))0))
77
78
/* Types of constants according to the C99 rules.  */
79
#define C99_UNSUF_TYPE(C)					\
80
	first_of6(int, (C) <= INT_MAX,				\
81
		  unsigned int, (C) <= UINT_MAX,		\
82
		  long int, (C) <= LONG_MAX,			\
83
		  unsigned long int, (C) <= ULONG_MAX,		\
84
		  long long int, (C) <= LLONG_MAX,		\
85
		  unsigned long long int, (C) <= ULLONG_MAX)
86
#define C99_SUFu_TYPE(C)					\
87
	first_of3(unsigned int, (C) <= UINT_MAX,		\
88
		  unsigned long int, (C) <= ULONG_MAX,		\
89
		  unsigned long long int, (C) <= ULLONG_MAX)
90
#define C99_SUFl_TYPE(C)					\
91
	first_of4(long int, (C) <= LONG_MAX,			\
92
		  unsigned long int, (C) <= ULONG_MAX,		\
93
		  long long int, (C) <= LLONG_MAX,		\
94
		  unsigned long long int, (C) <= ULLONG_MAX)
95
#define C99_SUFul_TYPE(C)					\
96
	first_of2(unsigned long int, (C) <= ULONG_MAX,		\
97
		  unsigned long long int, (C) <= ULLONG_MAX)
98
#define C99_SUFll_TYPE(C)					\
99
	first_of2(long long int, (C) <= LLONG_MAX,		\
100
		  unsigned long long int, (C) <= ULLONG_MAX)
101
102
/* Checks that constants have correct type.  */
103
#define CHECK_UNSUF_TYPE(C)				\
104
	ASSERT_CONST_TYPE((C), C99_UNSUF_TYPE((C)))
105
#define CHECK_SUFu_TYPE(C) ASSERT_CONST_TYPE((C), C99_SUFu_TYPE((C)))
106
#define CHECK_SUFl_TYPE(C)				\
107
	ASSERT_CONST_TYPE((C), C99_SUFl_TYPE((C)))
108
#define CHECK_SUFul_TYPE(C) ASSERT_CONST_TYPE((C), C99_SUFul_TYPE((C)))
109
#define CHECK_SUFll_TYPE(C)				\
110
	ASSERT_CONST_TYPE((C), C99_SUFll_TYPE((C)))
111
#define CHECK_SUFull_TYPE(C) ASSERT_CONST_TYPE((C), unsigned long long int)
112
113
/* Check an octal or hexadecimal value, with all suffixes.  */
114
#define CHECK_CONST(C)                  	\
115
	CHECK_UNSUF_TYPE(C);                    \
116
	CHECK_SUFu_TYPE(C##u);			\
117
	CHECK_SUFu_TYPE(C##U);			\
118
	CHECK_SUFl_TYPE(C##l);                  \
119
	CHECK_SUFl_TYPE(C##L);                  \
120
	CHECK_SUFul_TYPE(C##ul);		\
121
	CHECK_SUFul_TYPE(C##uL);		\
122
	CHECK_SUFul_TYPE(C##Ul);		\
123
	CHECK_SUFul_TYPE(C##UL);		\
124
	CHECK_SUFll_TYPE(C##ll);		\
125
	CHECK_SUFll_TYPE(C##LL);		\
126
	CHECK_SUFull_TYPE(C##ull);		\
127
	CHECK_SUFull_TYPE(C##uLL);		\
128
	CHECK_SUFull_TYPE(C##Ull);		\
129
	CHECK_SUFull_TYPE(C##ULL);
130
131
#define CHECK_BIN_CONST(C)			\
132
	CHECK_CONST(0b##C);                     \
133
	CHECK_CONST(0B##C);
134
135
/* True iff "long long" is at least B bits.  This presumes that (B-2)/3 is at
136
   most 63.  */
137
#define LLONG_AT_LEAST(B)			\
138
	(LLONG_MAX >> ((B)-2)/3 >> ((B)-2)/3	\
139
	 >> ((B)-2 - ((B)-2)/3 - ((B)-2)/3))
140
141
#define LLONG_HAS_BITS(B) (LLONG_AT_LEAST((B)) && !LLONG_AT_LEAST((B) + 1))
142
143
#define FOO 0b1101
144
#if !FOO
145
# error "preprocessor does not accept binary constants"
146
#endif
147
148
void
149
foo (void)
150
{
151
  /* Check all 2^n and 2^n - 1 up to 2^72 - 1.  */
152
  CHECK_BIN_CONST(1);
153
  CHECK_BIN_CONST(10);
154
  CHECK_BIN_CONST(11);
155
  CHECK_BIN_CONST(100);
156
  CHECK_BIN_CONST(111);
157
  CHECK_BIN_CONST(1000);
158
  CHECK_BIN_CONST(1111);
159
  CHECK_BIN_CONST(10000);
160
  CHECK_BIN_CONST(11111);
161
  CHECK_BIN_CONST(100000);
162
  CHECK_BIN_CONST(111111);
163
  CHECK_BIN_CONST(1000000);
164
  CHECK_BIN_CONST(1111111);
165
  CHECK_BIN_CONST(10000000);
166
  CHECK_BIN_CONST(11111111);
167
  CHECK_BIN_CONST(100000000);
168
  CHECK_BIN_CONST(111111111);
169
  CHECK_BIN_CONST(1000000000);
170
  CHECK_BIN_CONST(1111111111);
171
  CHECK_BIN_CONST(10000000000);
172
  CHECK_BIN_CONST(11111111111);
173
  CHECK_BIN_CONST(100000000000);
174
  CHECK_BIN_CONST(111111111111);
175
  CHECK_BIN_CONST(1000000000000);
176
  CHECK_BIN_CONST(1111111111111);
177
  CHECK_BIN_CONST(10000000000000);
178
  CHECK_BIN_CONST(11111111111111);
179
  CHECK_BIN_CONST(100000000000000);
180
  CHECK_BIN_CONST(111111111111111);
181
  CHECK_BIN_CONST(1000000000000000);
182
  CHECK_BIN_CONST(1111111111111111);
183
  CHECK_BIN_CONST(10000000000000000);
184
  CHECK_BIN_CONST(11111111111111111);
185
  CHECK_BIN_CONST(100000000000000000);
186
  CHECK_BIN_CONST(111111111111111111);
187
  CHECK_BIN_CONST(1000000000000000000);
188
  CHECK_BIN_CONST(1111111111111111111);
189
  CHECK_BIN_CONST(10000000000000000000);
190
  CHECK_BIN_CONST(11111111111111111111);
191
  CHECK_BIN_CONST(100000000000000000000);
192
  CHECK_BIN_CONST(111111111111111111111);
193
  CHECK_BIN_CONST(1000000000000000000000);
194
  CHECK_BIN_CONST(1111111111111111111111);
195
  CHECK_BIN_CONST(10000000000000000000000);
196
  CHECK_BIN_CONST(11111111111111111111111);
197
  CHECK_BIN_CONST(100000000000000000000000);
198
  CHECK_BIN_CONST(111111111111111111111111);
199
  CHECK_BIN_CONST(1000000000000000000000000);
200
  CHECK_BIN_CONST(1111111111111111111111111);
201
  CHECK_BIN_CONST(10000000000000000000000000);
202
  CHECK_BIN_CONST(11111111111111111111111111);
203
  CHECK_BIN_CONST(100000000000000000000000000);
204
  CHECK_BIN_CONST(111111111111111111111111111);
205
  CHECK_BIN_CONST(1000000000000000000000000000);
206
  CHECK_BIN_CONST(1111111111111111111111111111);
207
  CHECK_BIN_CONST(10000000000000000000000000000);
208
  CHECK_BIN_CONST(11111111111111111111111111111);
209
  CHECK_BIN_CONST(100000000000000000000000000000);
210
  CHECK_BIN_CONST(111111111111111111111111111111);
211
  CHECK_BIN_CONST(1000000000000000000000000000000);
212
  CHECK_BIN_CONST(1111111111111111111111111111111);
213
  CHECK_BIN_CONST(10000000000000000000000000000000);
214
  CHECK_BIN_CONST(11111111111111111111111111111111);
215
  CHECK_BIN_CONST(100000000000000000000000000000000);
216
  CHECK_BIN_CONST(111111111111111111111111111111111);
217
  CHECK_BIN_CONST(1000000000000000000000000000000000);
218
  CHECK_BIN_CONST(1111111111111111111111111111111111);
219
  CHECK_BIN_CONST(10000000000000000000000000000000000);
220
  CHECK_BIN_CONST(11111111111111111111111111111111111);
221
  CHECK_BIN_CONST(100000000000000000000000000000000000);
222
  CHECK_BIN_CONST(111111111111111111111111111111111111);
223
  CHECK_BIN_CONST(1000000000000000000000000000000000000);
224
  CHECK_BIN_CONST(1111111111111111111111111111111111111);
225
  CHECK_BIN_CONST(10000000000000000000000000000000000000);
226
  CHECK_BIN_CONST(11111111111111111111111111111111111111);
227
  CHECK_BIN_CONST(100000000000000000000000000000000000000);
228
  CHECK_BIN_CONST(111111111111111111111111111111111111111);
229
  CHECK_BIN_CONST(1000000000000000000000000000000000000000);
230
  CHECK_BIN_CONST(1111111111111111111111111111111111111111);
231
  CHECK_BIN_CONST(10000000000000000000000000000000000000000);
232
  CHECK_BIN_CONST(11111111111111111111111111111111111111111);
233
  CHECK_BIN_CONST(100000000000000000000000000000000000000000);
234
  CHECK_BIN_CONST(111111111111111111111111111111111111111111);
235
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000);
236
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111);
237
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000);
238
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111);
239
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000);
240
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111);
241
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000);
242
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111);
243
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000);
244
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111);
245
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000);
246
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111);
247
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000);
248
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111);
249
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000);
250
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111);
251
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000);
252
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111);
253
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000000);
254
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111111);
255
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000000);
256
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111111);
257
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000000);
258
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111111);
259
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000000000);
260
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111111111);
261
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000000000);
262
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111111111);
263
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000000000);
264
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111111111);
265
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000000000000);
266
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111111111111);
267
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000000000000);
268
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111111111111);
269
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000000000000);
270
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111111111111);
271
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000000000000000);
272
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111111111111111);
273
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000000000000000);
274
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111111111111111);
275
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000000000000000);
276
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111111111111111);
277
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000000000000000000);
278
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111111111111111111);
279
#if LLONG_AT_LEAST(65)
280
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000000000000000000);
281
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111111111111111111);
282
#endif
283
#if LLONG_AT_LEAST(66)
284
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000000000000000000);
285
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111111111111111111);
286
#endif
287
#if LLONG_AT_LEAST(67)
288
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000000000000000000000);
289
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111111111111111111111);
290
#endif
291
#if LLONG_AT_LEAST(68)
292
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000000000000000000000);
293
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111111111111111111111);
294
#endif
295
#if LLONG_AT_LEAST(69)
296
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000000000000000000000);
297
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111111111111111111111);
298
#endif
299
#if LLONG_AT_LEAST(70)
300
  CHECK_BIN_CONST(1000000000000000000000000000000000000000000000000000000000000000000000);
301
  CHECK_BIN_CONST(1111111111111111111111111111111111111111111111111111111111111111111111);
302
#endif
303
#if LLONG_AT_LEAST(71)
304
  CHECK_BIN_CONST(10000000000000000000000000000000000000000000000000000000000000000000000);
305
  CHECK_BIN_CONST(11111111111111111111111111111111111111111111111111111111111111111111111);
306
#endif
307
#if LLONG_AT_LEAST(72)
308
  CHECK_BIN_CONST(100000000000000000000000000000000000000000000000000000000000000000000000);
309
  CHECK_BIN_CONST(111111111111111111111111111111111111111111111111111111111111111111111111);
310
#endif
311
}
312
(-)gcc/testsuite/gcc.dg/binary-constants-3.c (+16 lines)
Line 0 Link Here
1
/* Test for binary integer constants: -pedantic-errors.  */
2
3
/* Origin: Joerg Wunsch <j.gnu@uriah.heep.sax.de>.  */
4
/* { dg-do compile } */
5
/* { dg-options "-std=iso9899:1999 -pedantic-errors" } */
6
7
#define FOO 0b1101
8
9
int
10
foo (void)
11
{
12
#if FOO /* { dg-error "binary constants are a GCC extension" } */
13
  return 23;
14
#endif
15
  return 0b1101; /* { dg-error "binary constants are a GCC extension" } */
16
}
(-)gcc/testsuite/gcc.dg/binary-constants-2.c (+16 lines)
Line 0 Link Here
1
/* Test for binary integer constants: -pedantic warnings.  */
2
3
/* Origin: Joerg Wunsch <j.gnu@uriah.heep.sax.de>.  */
4
/* { dg-do compile } */
5
/* { dg-options "-std=iso9899:1999 -pedantic" } */
6
7
#define FOO 0b1101
8
9
int
10
foo (void)
11
{
12
#if FOO /* { dg-warning "binary constants are a GCC extension" } */
13
  return 23;
14
#endif
15
  return 0b1101; /* { dg-warning "binary constants are a GCC extension" } */
16
}
(-)gcc/testsuite/gcc.dg/binary-constants-4.c (+18 lines)
Line 0 Link Here
1
/* Test for binary integer constants: random errors.  */
2
3
/* Origin: Joerg Wunsch <j.gnu@uriah.heep.sax.de>.  */
4
/* { dg-do compile } */
5
/* { dg-options "-std=gnu99" } */
6
7
void
8
foo(void)
9
{
10
  double d;
11
  int i;
12
13
  d = 0b1101;
14
  d = 0b1101p1; /* { dg-error "invalid suffix \"p1\" on integer constant" } */
15
  d = 0x1101p1;
16
  i = 0b3011;   /* { dg-error "invalid suffix \"b3011\" on integer constant" } */
17
  i = 0b113;    /* { dg-error "invalid digit \"3\" in binary constant" } */
18
}
(-)libcpp/include/cpplib.h (+1 lines)
Lines 744-749 Link Here
744
#define CPP_N_DECIMAL	0x0100
744
#define CPP_N_DECIMAL	0x0100
745
#define CPP_N_HEX	0x0200
745
#define CPP_N_HEX	0x0200
746
#define CPP_N_OCTAL	0x0400
746
#define CPP_N_OCTAL	0x0400
747
#define CPP_N_BINARY	0x0800
747
748
748
#define CPP_N_UNSIGNED	0x1000	/* Properties.  */
749
#define CPP_N_UNSIGNED	0x1000	/* Properties.  */
749
#define CPP_N_IMAGINARY	0x2000
750
#define CPP_N_IMAGINARY	0x2000
(-)libcpp/expr.c (-3 / +43 lines)
Lines 182-187 Link Here
182
	  radix = 16;
182
	  radix = 16;
183
	  str++;
183
	  str++;
184
	}
184
	}
185
      else if ((*str == 'b' || *str == 'B') && (str[1] == '0' || str[1] == '1'))
186
	{
187
	  radix = 2;
188
	  str++;
189
	}
185
    }
190
    }
186
191
187
  /* Now scan for a well-formed integer or float.  */
192
  /* Now scan for a well-formed integer or float.  */
Lines 220-229 Link Here
220
    radix = 10;
225
    radix = 10;
221
226
222
  if (max_digit >= radix)
227
  if (max_digit >= radix)
223
    SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
228
    {
229
      if (radix == 2)
230
	SYNTAX_ERROR2 ("invalid digit \"%c\" in binary constant", '0' + max_digit);
231
      else
232
	SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
233
    }
224
234
225
  if (float_flag != NOT_FLOAT)
235
  if (float_flag != NOT_FLOAT)
226
    {
236
    {
237
      if (radix == 2)
238
	{
239
	  cpp_error (pfile, CPP_DL_ERROR,
240
		     "invalid prefix \"0b\" for floating constant");
241
	  return CPP_N_INVALID;
242
	}
243
227
      if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
244
      if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
228
	cpp_error (pfile, CPP_DL_PEDWARN,
245
	cpp_error (pfile, CPP_DL_PEDWARN,
229
		   "use of C99 hexadecimal floating constant");
246
		   "use of C99 hexadecimal floating constant");
Lines 308-318 Link Here
308
  if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
325
  if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
309
    cpp_error (pfile, CPP_DL_PEDWARN,
326
    cpp_error (pfile, CPP_DL_PEDWARN,
310
	       "imaginary constants are a GCC extension");
327
	       "imaginary constants are a GCC extension");
328
  if (radix == 2 && CPP_PEDANTIC (pfile))
329
    cpp_error (pfile, CPP_DL_PEDWARN,
330
	       "binary constants are a GCC extension");
311
331
312
  if (radix == 10)
332
  if (radix == 10)
313
    result |= CPP_N_DECIMAL;
333
    result |= CPP_N_DECIMAL;
314
  else if (radix == 16)
334
  else if (radix == 16)
315
    result |= CPP_N_HEX;
335
    result |= CPP_N_HEX;
336
  else if (radix == 2)
337
    result |= CPP_N_BINARY;
316
  else
338
  else
317
    result |= CPP_N_OCTAL;
339
    result |= CPP_N_OCTAL;
318
340
Lines 363-368 Link Here
363
	  base = 16;
385
	  base = 16;
364
	  p += 2;
386
	  p += 2;
365
	}
387
	}
388
      else if ((type & CPP_N_RADIX) == CPP_N_BINARY)
389
	{
390
	  base = 2;
391
	  p += 2;
392
	}
366
393
367
      /* We can add a digit to numbers strictly less than this without
394
      /* We can add a digit to numbers strictly less than this without
368
	 needing the precision and slowness of double integers.  */
395
	 needing the precision and slowness of double integers.  */
Lines 418-429 Link Here
418
append_digit (cpp_num num, int digit, int base, size_t precision)
445
append_digit (cpp_num num, int digit, int base, size_t precision)
419
{
446
{
420
  cpp_num result;
447
  cpp_num result;
421
  unsigned int shift = 3 + (base == 16);
448
  unsigned int shift;
422
  bool overflow;
449
  bool overflow;
423
  cpp_num_part add_high, add_low;
450
  cpp_num_part add_high, add_low;
424
451
425
  /* Multiply by 8 or 16.  Catching this overflow here means we don't
452
  /* Multiply by 2, 8 or 16.  Catching this overflow here means we don't
426
     need to worry about add_high overflowing.  */
453
     need to worry about add_high overflowing.  */
454
  switch (base)
455
    {
456
    case 2:
457
      shift = 1;
458
      break;
459
460
    case 16:
461
      shift = 4;
462
      break;
463
464
    default:
465
      shift = 3;
466
    }
427
  overflow = !!(num.high >> (PART_PRECISION - shift));
467
  overflow = !!(num.high >> (PART_PRECISION - shift));
428
  result.high = num.high << shift;
468
  result.high = num.high << shift;
429
  result.low = num.low << shift;
469
  result.low = num.low << shift;

Return to bug 23479