Binary Escapes
Mike Macgirvin
mike at relgyro.stanford.edu
Wed Nov 22 07:34:06 AEST 1989
Following are context diffs to allow binary escapes under
gcc-1.35. You must define BINARY_STUFF in config.h for this stuff
to work.
Disclaimer:
Applying these patches will make gcc non-ANSI compliant. Any
code you develop using the binary escapes will be non-portable. Whether
or not the ANSI standard 'C' should use similiar constructs is irrelevant,
and the author does not wish to debate the subject, nor encourage the
practice of writing non-ANSI compliant code.
The author assumes no responsibility for any use of this code.
Use at your own risk. I do not guarantee that these patches are bug-free.
They have been tested on a Sun 3/260 running SunOS 3.5.
Summary:
Allows the C compiler to generate code for binary escape
sequences. These may be of two forms:
0[bB]{some binary number}
i.e. int x = 0B01000001;
or as a string escape:
"\B{some binary number}"
i.e. printf("\B01000001\n");
(The string escape cannot be lower case because it would
interfere with the ANSI backspace sequence '\b').
*** c-parse.y Tue Nov 21 11:32:21 1989
--- c-parse.y.orig Tue Nov 21 10:27:50 1989
***************
*** 1790,1824 ****
switch (c)
{
- #ifdef BINARY_STUFF
- case 'B':
- code = 0;
- count = 0;
- while (1)
- {
- c = getc (finput);
- if(! ((c == '0') || (c == '1')))
- {
- ungetc (c, finput);
- break;
- }
- code *= 2;
- if(c == '1')
- code += c - '0';
- if(count == 0)
- firstdig = code;
- count ++;
- }
- if (count == 0)
- error ("\\B used with no following binary digits");
- if ((count - 1) >= TYPE_PRECISION (integer_type_node)
- || ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1)))
- <= firstdig))
- warning ("binary escape out of range");
- return code;
-
- #endif /* BINARY_STUFF */
-
case 'x':
code = 0;
count = 0;
--- 1790,1795 ----
***************
*** 2111,2123 ****
base = 16;
*p++ = (c = getc (finput));
}
- #ifdef BINARY_STUFF
- else if ((c == 'b') || (c == 'B'))
- {
- base = 2;
- *p++ = (c = getc (finput));
- }
- #endif /* BINARY_STUFF */
else
{
base = 8;
--- 2082,2087 ----
*** cexp.y Tue Nov 21 10:42:22 1989
--- cexp.y.orig Tue Nov 21 11:42:41 1989
***************
*** 188,201 ****
base = 16;
len -= 2;
}
- #ifdef BINARY_STUFF
- else
- if (len >= 3 && (!strncmp (p, "0b", 2) || !strncmp (p, "0B", 2))) {
- p += 2;
- base = 2;
- len -= 2;
- }
- #endif /* BINARY_STUFF */
else if (*p == '0')
base = 8;
--- 188,193 ----
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Mike Macgirvin Relativity Gyroscope Experiment (GP-B) +
+ mike at relgyro.stanford.edu (36.64.0.50) +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
More information about the Comp.lang.c
mailing list