Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!ginosko!uunet!yale!mfci!karzes From: karzes@mfci.UUCP (Tom Karzes) Newsgroups: comp.lang.c Subject: cpp behavior Message-ID: <1077@m3.mfci.UUCP> Date: 12 Oct 89 17:48:47 GMT Sender: karzes@mfci.UUCP Reply-To: karzes@mfci.UUCP (Tom Karzes) Organization: Multiflow Computer Inc., Branford Ct. 06405 Lines: 85 I have a couple of questions about correct cpp behavior. I have tried the following test on several different machines with pcc-derived compilers (and presumably standard cpp's as well), and all give the same results: % cat test1 #define M1()+++ M1() #define M2+++ M2 #define M3()=== M3() #define M4=== M4 % /lib/cpp test1 # 1 "test1" +++ ++ === = % The results for M1 and M3 were what I expected, but I also would have expected the results for M2 to be identical to the results for M1, and the results for M4 to be identical to the results for M3. Note that there appears to be something special about =, since cpp eats two of them. For other characters it only eats one. But why should it eat any? Please try this on your own machine before responding (if for no other reason than to see if it does the same thing). Here's a second test, which again gives the same results on several different machines: % cat test2 #define M1 123 #if M1 == 123 xxx #endif #define M2() 456 #if M2() == 456 yyy #endif #define M3(x) x #if M3(789) == 789 zzz #endif % /lib/cpp test2 # 1 "test2" xxx test2: 9: syntax error 456 == 456 yyy #endif test2: 14: syntax error 789 == 789 zzz #endif test2: 15: missing endif % The M1 case did what I expected, i.e., it expanded M1, then evaluated 123 == 123, which resulted in a value of 1, so xxx was passed through. However, for both the M2 and M3 cases it appears that the macro was expanded, but rather than consuming the results, it instead placed them into the output, and forgot that it was processing an #if directive. This seems like a clear bug to me. Even if there is some rule about only using unparameterized macros in #if expressions (which seems stupid), I would have expected a sane error message. Please try this on your own machine before responding (if for no other reason than to see if it does the same thing).