binary constants (??)

Norman Diamond diamond at csl.sony.co.jp
Tue Nov 21 21:11:23 AEST 1989


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]*

The ISO Extended Pascal standard has numbers almost exactly like this.
The syntax is base#expr, expr is of the form [0-9a-zA-Z][0-9a-zA-Z]*,
and any value from 2 to 36 is legal for the base.  "expr" must be a
constant though, not really an expr.  (base must be a constant too.)

This could be added as an extension to C, except that if "expr" happens
to match a formal parameter name in a macro expansion then the expr
must be stringized instead.  Alternatively, Mr. Torek's syntax could
always be accepted as an extension, because #( is never legal in X3J11.
(The processor would have to give a warning before accepting it.
I think.)

-- 
Norman Diamond, Sony Corp. (diamond%ws.sony.junet at uunet.uu.net seems to work)
  Should the preceding opinions be caught or     |  James Bond asked his
  killed, the sender will disavow all knowledge  |  ATT rep for a source
  of their activities or whereabouts.            |  licence to "kill".



More information about the Comp.lang.c mailing list