Macro parameters getting substituted into strings

Arthur David Olson ado at elsie.UUCP
Mon Mar 28 07:00:50 AEST 1988


In article <4253 at hoptoad.uucp>, gnu at hoptoad.uucp (John Gilmore) writes:
> I am not saying that I like the idea of macro parameter names being
> replaced even inside strings.  My complaint is that an ANSI C compiler
> does not have a capability that Unix C compilers have, and which many
> Unix programs depend upon.  This is the capability to turn a single-
> character argument into a character constant.  MOVING TO ANSI C REQUIRES
> CHANGING ALL THE **USES**, AS WELL AS ALL THE **DEFINITIONS**, OF MACROS
> THAT NEED THIS CAPABILITY!

Here's an example (taken from "/usr/include/sys/ttychars.h") of how we coped
with the problem here at elsie; this avoids the need to change *most* uses;
you'll get complaints about the ones that do need special attention.

	#if !defined __STDC__ && !defined __DECUS_CPP__
	#define	CTRL(c)	('c'&037)
	#else /* defined __STDC__  || defined __DECUS_CPP__ */
	#ifndef LETR_a
	#define LETR_a	'a'
	#define LETR_b	'b'
	#define LETR_c	'c'
	#define LETR_d	'd'
	#define LETR_e	'e'
	#define LETR_f	'f'
	#define LETR_g	'g'
	#define LETR_h	'h'
	#define LETR_i	'i'
	#define LETR_j	'j'
	#define LETR_k	'k'
	#define LETR_l	'l'
	#define LETR_m	'm'
	#define LETR_n	'n'
	#define LETR_o	'o'
	#define LETR_p	'p'
	#define LETR_q	'q'
	#define LETR_r	'r'
	#define LETR_s	's'
	#define LETR_t	't'
	#define LETR_u	'u'
	#define LETR_v	'v'
	#define LETR_w	'w'
	#define LETR_x	'x'
	#define LETR_y	'y'
	#define LETR_z	'z'
	#define LETR_A	'A'
	#define LETR_B	'B'
	#define LETR_C	'C'
	#define LETR_D	'D'
	#define LETR_E	'E'
	#define LETR_F	'F'
	#define LETR_G	'G'
	#define LETR_H	'H'
	#define LETR_I	'I'
	#define LETR_J	'J'
	#define LETR_K	'K'
	#define LETR_L	'L'
	#define LETR_M	'M'
	#define LETR_N	'N'
	#define LETR_O	'O'
	#define LETR_P	'P'
	#define LETR_Q	'Q'
	#define LETR_R	'R'
	#define LETR_S	'S'
	#define LETR_T	'T'
	#define LETR_U	'U'
	#define LETR_V	'V'
	#define LETR_W	'W'
	#define LETR_X	'X'
	#define LETR_Y	'Y'
	#define LETR_Z	'Z'
	#endif /* !LETR_a */
	#define CTRL(c)	((LETR_ ## c) & 037)
	#endif /* defined __STDC__  || defined __DECUS_CPP__ */
-- 
olson at ncifcrf.gov	". . .that lucky ol' Sun ain't got nothin' to do. . ."



More information about the Comp.lang.c mailing list