Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!ginosko!aplcen!haven!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Pascal to C (and vice versa) Message-ID: <20355@mimsy.umd.edu> Date: 24 Oct 89 01:32:39 GMT References: <5164@uhccux.uhcc.hawaii.edu> <4640@mentor.cc.purdue.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 47 In article <4640@mentor.cc.purdue.edu> acu@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@cs.umd.edu Path: uunet!mimsy!chris