I believe you. I am not a C macro or C history expert. I have not tried your first example but I believe you.
I hear you on your debug(x) example. Without the # operator there is no way (?) to accomplish that. I do think that the distinction between the two cases is confusing, and I do think that it is a trap for the unwary. (I suppose some would argue that all of C is a trap for the unwary LOL.) I think my associate just stumbled into this. A macro with formal arguments named a, b, c and d does not seem unreasonable, and %d is certainly not uncommon in strings. > The person writing a macro with arguments has full control over the names Yes, but a person writing a pre-compiler (in the generic sense of "some program that processes source code in some way before a compiler") as my associate is doing does not. The fact that the same "bug" exists in the HP non-ANSI C compiler would indicate that either the two compilers have common roots (not implausible) or else that this was indeed standard behavior pre-ANSI. It's interesting. I Googled multiple variations of the subject of this e-mail before posting and all I got was lots of tutorials on # and newbie forum questions about #. But adding "non-ANSI" to the search yielded http://www.abxsoft.com/ansicc.htm (check out rule 8006), http://northstar-www.dartmouth.edu/doc/solaris-forte/manuals/c/user_guide/tg uide.html#713 (watch the fold and see "Using Strings") and http://stratadoc.stratus.com/vos/15.1.1/r040m-00/wwhelp/wwhimpl/js/html/wwhe lp.htm?context=r040m-00&file=ch1r040m-00i.html (watch the fold). Thanks! I think you have solved the mystery. Charles -----Original Message----- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf Of glen herrmannsfeldt Sent: Thursday, September 04, 2014 2:37 AM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: IBM C compiler substituting for macros inside literals? > it must be bug with the macro preprocessor used by USS's cc comand. > Even K&R's 1978 definition of C makes it clear that arguments inside > "..." strings are not to be substituted. Two different questions. If you: #define d 5 printf("%d", 3); the d won't be replaced. That is, in preprocessor terms, a very different question from: #define S(d) printf("%d", d) The person writing a macro with arguments has full control over the names, and can choose them to match or not. This allows for: #define debug(x) printf("x=%d\n", x) ANSI added the stringizing operation, and then removed the replacement inside strings. While not explicitely stated in K&R1, it is the normal case for non-ANSI preprocessors. ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN