CTRL(x)

Daniel R. Levy levy at ttrdc.UUCP
Wed Nov 5 16:10:40 AEST 1986


In article <666 at dg_rtp.UUCP>, meissner at dg_rtp.UUCP (Michael Meissner) writes:
>In article <4880 at brl-smoke.ARPA> kb5mu at NOSC.ARPA writes:
>>        #define CTRL(c) (#c[0] & 037)
>>This should turn
>>        CTRL(z)
>>into
>>        ("z"[0] & 037)
>The problem with using string-izing, is that it is not a constant expression,
>and can't be used in switch statements.  Many of the places CTRL(x) is
>currently used ARE in switch statements.  Another approach would be to use
>token pasting, instead of string-izing:
>
>	enum _ctrl_chars {
>		_ctrl_a = 1,
>		...
>		_ctrl_Z = 26
>	};
>	#define CTRL(x)		(int)( _ctrl_ ## x)
>The problem with the above is that people have also used CTRL([) to
>represent the escape character.
>	Michael Meissner, Data General

At this point, I begin to wonder out loud why all the contortions people are
going to just to avoid typing two silly little single quotes when using a
CTRL macro, i.e.:

#define CTRL(x) (x & 037)

	char c;
	switch (c) {
		CTRL('A'):	blah blah blah...; break;
		CTRL('E'):	bleh bleh bleh...; break;
		...

This even lets you have your CTRL('@') for NUL and CTRL('[') for escape, etc.
I contend this is just as useful as anyone else's suggestion and doesn't rely
on any large list of values or fancy-ANSI [:-)] preprocessor either.
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!{akgua,homxb,ihnp4,ltuxa,mvuxa,
	   go for it!  			allegra,ulysses,vax135}!ttrdc!levy



More information about the Comp.lang.c mailing list