binary constants
Clive Feather
clive at ixi.co.uk
Wed Nov 22 18:29:52 AEST 1989
[I finally get to follow up to Chris Torek]
In article <20830 at mimsy.umd.edu> chris at mimsy.umd.edu (Chris Torek) writes:
>One of my favourite silly ideas for C is now ruled out by X3J11's
>`#' `stringize' preprocessing operator (or at least, would require
>some other syntax), but it went like this: Instead of having hex,
>decimal, octal, binary, etc., constant syntaxes, why not have a
>single syntax for `based numbers'? The initial radix would always
>be decimal; the format would be something like
> #(base,expr)
>Numbers in the `expr' part would be interpreted in the base given by
>the `base' expression. Any value from 2 to 36 would be legal for the
>base. All `numbers' would be of the form
> [0-9][0-9a-zA-Z]*
>where ordinary digits represent themselves and letters represent digits
>>= 10 in the obvious manner. (Whether digits greater than the base
>would be legal is essentially irrelevant.)
Algol 68 (yes, some of us once used it) uses the following notation for bit
patterns:
2r11001000 == 200
4r3020 == 200
8r310 == 200
16rc8 == 200
This could be trivially extended to any base up to 36. It has advantages over
Chris's notation, in that the numbers are already pp-numbers (see the
discussion in comp.std.c), and it doesn't use a new operator.
>The sneaky (or silly) bit is that both `base' and `expr' would be
>arbitrary constant expressions. This would be useful for obfuscation
>such as
> #(3+#(2,#(6,13)-0010),#(5,11)/30)
>which is actually 1.
>(I think.)
You're right - silly is the word :-).
--
Clive D.W. Feather
IXI Limited
clive at ixi.uucp
...!uunet!ukc!ixi!clive (riskier)
More information about the Comp.lang.c
mailing list