[comp.lang.c] Define CTRL

mzal@phoenix.UUCP (Mike Zaleski) (11/14/86)

[...]

If one wants to do CTRL(X) and have it appear as though the character
'^X' was in the source text, this can be done without single quotes by:

# include	<stdio.h>
# define	CTRL(ZZ)	( (int) (*"ZZ" & 037) )

main () {
	fprintf (stdout, "%d %d %d %d\n", CTRL(A), CTRL(B), CTRL(Z), CTRL(@));
	exit (0);
}

This is not bulletproof, since CTRL(") will cause compilation errors and
some characters (like DEL) won't work with this.  But if you just wanted
CTRL(A) .. CTRL(Z), this seems fairly straightforward.

It worked on our System Vr2 C compiler.

-- "The Model Citizen" Mike^Z
   [ allegra, ihnp4 ] phoenix!mzal     Zaleski@Rutgers.Arpa