Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!amdcad!ames!nrl-cmf!cmcl2!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: macros with parameters in MSC 5.0 Message-ID: <7277@brl-smoke.ARPA> Date: 18 Feb 88 22:10:56 GMT References: <11879@brl-adm.ARPA> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 25 In article <11879@brl-adm.ARPA> jbaker@ee.UCLA.EDU (Joe Baker) writes: >#define ctl(c) ('c'&037) Yes, whoever did this was deliberately violating the K&R rules, because they knew that their C preprocessor (probably based on Reiser's) would allow it. This particular macro and Berkeley's _IOR etc. ioctl macros are the most common cases of this nonportable construct. Neither was necessary, since the desired effect could have been achieved portably. The correct way to have done this would have been: #define ctl(c) ((c)&037) and include the '' in its invocation: case ctl('G'): With ANSI C, or any C preprocessor that includes the stringizing feature, you can make the original usage work by #define ctl(c) (#c[0]&037) which would cause case ctl(G): to expand to case ("G"[0]&037): which is equivalent to case ('G'&037): Personally, I prefer the other way I described, because it also works with pre-ANSI C preprocessors.