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

Collapse All | Expand All

(-)./gcc/doc/extend.texi.orig (+23 lines)
Lines 79-84 Link Here
79
* Pragmas::             Pragmas accepted by GCC.
79
* Pragmas::             Pragmas accepted by GCC.
80
* Unnamed Fields::      Unnamed struct/union fields within structs/unions.
80
* Unnamed Fields::      Unnamed struct/union fields within structs/unions.
81
* Thread-Local::        Per-thread variables.
81
* Thread-Local::        Per-thread variables.
82
* Binary constants::    Binary constants using the @samp{0b} prefix.
82
@end menu
83
@end menu
83
84
84
@node Statement Exprs
85
@node Statement Exprs
Lines 9742-9747 Link Here
9742
Non-@code{static} members shall not be @code{__thread}.
9743
Non-@code{static} members shall not be @code{__thread}.
9743
@end quotation
9744
@end quotation
9744
@end itemize
9745
@end itemize
9746
9747
@node Binary constants
9748
@section Binary constants using the @samp{0b} prefix
9749
@cindex Binary constants using the @samp{0b} prefix
9750
9751
Integer constants can be written as binary constants, consisting of a
9752
sequence of @samp{0} and @samp{1} digits, prefixed by @samp{0b} or
9753
@samp{0B}.  This is particularly useful in environments that operate a
9754
lot on the bit-level (like microcontrollers).
9755
9756
The following statements are identical:
9757
9758
@smallexample
9759
i =       42;
9760
i =     0x2a;
9761
i =      052;
9762
i = 0b101010;
9763
@end smallexample
9764
9765
The type of these constants follows the same rules as for octal or
9766
hexadecimal integer constants, so suffixes like @samp{L} or @samp{UL}
9767
can be applied.
9745
9768
9746
@node C++ Extensions
9769
@node C++ Extensions
9747
@chapter Extensions to the C++ Language
9770
@chapter Extensions to the C++ Language
(-)./libcpp/include/cpplib.h.orig (+1 lines)
Lines 729-734 Link Here
729
#define CPP_N_DECIMAL	0x0100
729
#define CPP_N_DECIMAL	0x0100
730
#define CPP_N_HEX	0x0200
730
#define CPP_N_HEX	0x0200
731
#define CPP_N_OCTAL	0x0400
731
#define CPP_N_OCTAL	0x0400
732
#define CPP_N_BINARY	0x0800
732
733
733
#define CPP_N_UNSIGNED	0x1000	/* Properties.  */
734
#define CPP_N_UNSIGNED	0x1000	/* Properties.  */
734
#define CPP_N_IMAGINARY	0x2000
735
#define CPP_N_IMAGINARY	0x2000
(-)./libcpp/expr.c.orig (-1 / +28 lines)
Lines 171-176 Link Here
171
	  radix = 16;
171
	  radix = 16;
172
	  str++;
172
	  str++;
173
	}
173
	}
174
      else if ((*str == 'b' || *str == 'B') && (str[1] == '0' || str[1] == '1'))
175
	{
176
	  radix = 2;
177
	  str++;
178
	}
174
    }
179
    }
175
180
176
  /* Now scan for a well-formed integer or float.  */
181
  /* Now scan for a well-formed integer or float.  */
Lines 209-218 Link Here
209
    radix = 10;
214
    radix = 10;
210
215
211
  if (max_digit >= radix)
216
  if (max_digit >= radix)
212
    SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
217
    {
218
      if (radix == 2)
219
	SYNTAX_ERROR2 ("invalid digit \"%c\" in binary constant", '0' + max_digit);
220
      else
221
	SYNTAX_ERROR2 ("invalid digit \"%c\" in octal constant", '0' + max_digit);
222
    }
213
223
214
  if (float_flag != NOT_FLOAT)
224
  if (float_flag != NOT_FLOAT)
215
    {
225
    {
226
      if (radix == 2)
227
	{
228
	  cpp_error (pfile, CPP_DL_ERROR,
229
		     "invalid prefix \"0b\" for floating constant");
230
	  return CPP_N_INVALID;
231
	}
232
216
      if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
233
      if (radix == 16 && CPP_PEDANTIC (pfile) && !CPP_OPTION (pfile, c99))
217
	cpp_error (pfile, CPP_DL_PEDWARN,
234
	cpp_error (pfile, CPP_DL_PEDWARN,
218
		   "use of C99 hexadecimal floating constant");
235
		   "use of C99 hexadecimal floating constant");
Lines 288-298 Link Here
288
  if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
305
  if ((result & CPP_N_IMAGINARY) && CPP_PEDANTIC (pfile))
289
    cpp_error (pfile, CPP_DL_PEDWARN,
306
    cpp_error (pfile, CPP_DL_PEDWARN,
290
	       "imaginary constants are a GCC extension");
307
	       "imaginary constants are a GCC extension");
308
  if (radix == 2 && CPP_PEDANTIC (pfile))
309
    cpp_error (pfile, CPP_DL_PEDWARN,
310
	       "binary constants are a GCC extension");
291
311
292
  if (radix == 10)
312
  if (radix == 10)
293
    result |= CPP_N_DECIMAL;
313
    result |= CPP_N_DECIMAL;
294
  else if (radix == 16)
314
  else if (radix == 16)
295
    result |= CPP_N_HEX;
315
    result |= CPP_N_HEX;
316
  else if (radix == 2)
317
    result |= CPP_N_BINARY;
296
  else
318
  else
297
    result |= CPP_N_OCTAL;
319
    result |= CPP_N_OCTAL;
298
320
Lines 341-346 Link Here
341
      else if ((type & CPP_N_RADIX) == CPP_N_HEX)
363
      else if ((type & CPP_N_RADIX) == CPP_N_HEX)
342
	{
364
	{
343
	  base = 16;
365
	  base = 16;
366
	  p += 2;
367
	}
368
      else if ((type & CPP_N_RADIX) == CPP_N_BINARY)
369
	{
370
	  base = 2;
344
	  p += 2;
371
	  p += 2;
345
	}
372
	}
346
373

Return to bug 23479