public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* preprocessor weirdness
@ 2000-07-09 20:23 lindholm
  2000-07-10  3:32 ` Neil Booth
  0 siblings, 1 reply; 2+ messages in thread
From: lindholm @ 2000-07-09 20:23 UTC (permalink / raw)
  To: gcc

I'm trying to get g++ to parse the Win2k DDK header files (not to produce
code, it's for a semantic-checking project). I came across an error on
this rather unusual code (in wtypes.h of the DDK):

#if !__STDC__ && (_MSC_VER <= 1000)
/* For backward compatibility */
typedef VARIANT_BOOL _VARIANT_BOOL;

#else
/* ANSI C/C++ reserve bool as keyword */
#define _VARIANT_BOOL    /##/
#endif

I take it that, under VC++, _VARIANT_BOOL is now equal to "//" and where
it appears later in code, it comments out the rest of the line. That
doesn't happen in g++, it gives me an error:

/home/lindholm/WINDDK/2195/inc/oaidl.h:439: parse error before `/'
/home/lindholm/WINDDK/2195/inc/oaidl.h:454: parse error before `/'

I've never seen anything like this before, so I'm guessing that the author
was just taking advantage of a quirk in the VC++ parser. Is this right?
This isn't ANSI-compliant code, is it?



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: preprocessor weirdness
  2000-07-09 20:23 preprocessor weirdness lindholm
@ 2000-07-10  3:32 ` Neil Booth
  0 siblings, 0 replies; 2+ messages in thread
From: Neil Booth @ 2000-07-10  3:32 UTC (permalink / raw)
  To: lindholm; +Cc: gcc

lindholm@possessive.stanford.edu wrote:-

> /* ANSI C/C++ reserve bool as keyword */
> #define _VARIANT_BOOL    /##/
> #endif
> 
> I take it that, under VC++, _VARIANT_BOOL is now equal to "//" and where
> it appears later in code, it comments out the rest of the line. That
> doesn't happen in g++, it gives me an error:

Yuk.  Experimenting I've discovered that Borland and MS use a
single-pass text-based preprocessor (MS are clever in that they get
trigraphs almost right in the single pass, Borland don't bother with
trigraphs and just provide a filter).

MS chose to do it so that the above thing is rescanned by the same
code that recognises comments, turning the line into a comment.  As
Geoff said, this is definitely wrong.  Indeed, it's even given as an
example of wrongness in the standard (6.4.9 para 3):-

#define glue(x, y) x##y
glue(/, /)k();   // syntax error, not a comment.

They get a whole load of other things wrong in the preprocessor, too.
Unfortunately for Borland they have to compile MS headers and code, so
they have no choice but to copy most of MS breakage.

I think the chances of GCC ever accepting this are close to zero.

Neil.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-07-10  3:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-09 20:23 preprocessor weirdness lindholm
2000-07-10  3:32 ` Neil Booth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).