[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::decc_bugs

Title:DEC C Problem Reporting Forum
Notice:Report DEC C++ problems in TURRIS::C_PLUS_PLUS
Moderator:CXXC::REPETETCHEON
Created:Fri Nov 13 1992
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:1299
Total number of notes:6249

1267.0. "POSSIBLE DEC C PREPROCESSOR BUG (OPENVMS)" by TAV02::MILCHIN () Tue Feb 25 1997 02:37

	HI!

	It seems that DEC C preprocessor (OPENVMS VAX and ALPHA) has a problem
with macro expansion. If the macro definition contains another macro
on its right side, the result of the right-side macro expansion string
is padded by a single-blank.
	Look at the following example:

#define MMMDEF() M
#define MMM(Z) MMMDEF()Z

int main() {
 int i;
 extern int MMM(_a)(int);
 i = MMM(_a)(5);
 return 1;
}

	$ CC/PREPROC/DEFINE=M=ABC A

# 1 "TSC:[MICHAEL]A.C;8"



int main() {
 int i;
 extern int ABC _a(int);
 i = ABC _a(5);
 return 1;
}

	Indeed, the compilation will produce errors of the type %CC-E-NOSEMI,...
	The problem disappears when compiling with /STANDARD=VAXC, but this
work-arround does not applicable to the customer.
(DEC C V5.5 for OPENVMS VAX and ALPHA).

		MICHAEL
T.RTitleUserPersonal
Name
DateLines
1267.1##MUCTEC::BECKERHartmut B., VMS & Languages, MunichTue Feb 25 1997 04:3523
The ANSI C preprocessor has to tokenize the input stream into C language
tokens. That is it places white spaces between the recognized tokens. Hence a
concatenation with you construct isn't possible. It works with pre-ANSI
preprocessors as vaxc. This was mentioned before in this conference and the
DECC notes conference. There are also a lot of examples how to do token
concatenation with macros in ANSI C. This is done with the ## operator which is
evaluated in macro replacements. I suggest

#if __STDC__
#define _MMMDEF(a,b) a##b
#define MMMDEF(M,Z) _MMMDEF(M,Z)
#define MMM(Z) MMMDEF(M,Z)
#else
#define MMMDEF() M
#define MMM(Z) MMMDEF()Z
#endif

The additional macro is necessary to have M expanded before it is passed to the
real concatenation, the ##.

Hope this helps,
Hartmut
    
1267.2TAV02::MILCHINTue Feb 25 1997 09:225
	RE -.1:

	Thank you for your quick and clear reply. I passed this information
to the customer and he was satisfied.
		MICHAEL
1267.3Avoid _MMMDEF, squirrelly __STDC__CXXC::REPETERich Peterson 381-1802 ZKO2-3/N30Wed Feb 26 1997 13:5924
RE .1:

> #if __STDC__
> #define _MMMDEF(a,b) a##b
> #define MMMDEF(M,Z) _MMMDEF(M,Z)

Hartmut's answer was great, but I'd add two little cautions to it:

1.  The helper macro _MMMDEF should be named something else.  An
    identifier beginning with an underscore followed by an uppercase
    letter (or another underscore) is reserved to the C language
    implementation and should never by declared or defined as a macro
    in a user's source code.

2.  The test "#if __STDC__" is equivalent to "#if __STDC__ != 0".  This
    will be TRUE for a strictly-conforming compiler mode (in which it is
    required that __STDC__ == 1), and also for a huge number of situations
    which are undefined by the standard (where the value of the macro is
    nonzero but not 1).  In particular, it will be FALSE if __STDC__ is
    defined with a value of 0 - but defining __STDC__ to 0 just happens
    to be a relatively common practice among UNIX compilers (including
    Digital UNIX and System V compilers) to indicate a relaxed-ANSI
    mode, which normally means that K&R-style token pasting will not
    be done.  So a better test in this case would be "#if defined (__STDC__)".