Pascal to C (and vice versa)

Chris Torek chris at mimsy.umd.edu
Tue Oct 24 11:32:39 AEST 1989


In article <4640 at mentor.cc.purdue.edu> acu at mentor.cc.purdue.edu
(Floyd McWilliams) writes:
[various C constructs that cannot be expressed efficiently in Pascal]
>	Or, for that matter, how a Pascal-to-C converter would take:
>	var
>	  X : set of char;
>	X := ['a','b','c'];
>	if 'a' in X then
>	  X := X + 'A'
>	else
>	  X := X * ['b','c'];

It is worth noting that the above is not standard Pascal (unless, as
is not too terribly unlikely, I have missed something that happened
recently in Pascal standards).  Pascal sets are limited to some small
number of possible members.  Some (many/most/almost-all) implementations
allow larger sets (such as `set of char'), but the standard requires
only a small number of elements per set.  It does not say exactly what
that number might be, only that it is `small' and has to do with the
machine's word size.  The limit might be, e.g., 36 (as it was in various
36-bit machine Pascals).  `set of char' usually requires at least 64.

Anyway, a Pascal-to-C converter could treat this as

	twofiftysixbitinteger X;
	X = bit('a') | bit('b') | bit('c');
	if (X & bit('a'))
		X |= bit('A');
	else
		X &= bit('b') | bit('c');

if you had 256-bit integers.  As it is, this sort of thing normally
requires bit-manipulation macros:

	SET(X, 256);	/* char X[(256+7)/8] */
	ZAPSET(X, 256),	/* memset to 0, 256 bits */
		BIS(X, 'a'), BIS(X, 'b'), BIS(X, 'c');
	if (BIT(X, 'a'))
		BIS(X, 'A');
	else
		SETINTERSECT(X, 256, 'b'), SETINTERSECT(X, 256, 'c');

which (as you can see) is not very nice.
-- 
`They were supposed to be green.'
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list