Topic: C++ and __STDC__


Author: tkacik@adtaz.sps.mot.com (Tom Tkacik)
Date: Fri, 4 Jun 1993 16:08:54 GMT
Raw View
We have recently installed a new version of C++ based on cfront 3.0.
It defines __STDC__.  Is it proper for a C++ compiler to identify itself
as ANSI C?  It does use the ANSI C semantics, and has an ANSI preprocessor.


Thank you.

Tom Tkacik
Motorola Inc.
tkacik@adtaz.sps.mot.com







Author: cflatter@nrao.edu (Chris Flatters)
Date: Fri, 4 Jun 93 17:30:51 GMT
Raw View
In article 13023@newsgate.sps.mot.com, tkacik@adtaz.sps.mot.com (Tom Tkacik) writes:
>We have recently installed a new version of C++ based on cfront 3.0.
>It defines __STDC__.  Is it proper for a C++ compiler to identify itself
>as ANSI C?  It does use the ANSI C semantics, and has an ANSI preprocessor.

Defining __STDC__ does not necessarily identify a compiler as an ANSI C compiler.
ANSI C compilers are required to set __STDC__ to 1.  SunPro's port of cfront 3.0
(and presumably other ports) sets __STDC__ to 0 so there is no conflict.

NB: the ANSI C standard does not make any strictures about C++ so C++ compilers
(and non-ANSI C compilers) are free to do what they like with __STDC__, including
setting it to 1.

 Chris Flatters
 cflatter@nrao.edu





Author: tkacik@adtaz.sps.mot.com (Tom Tkacik)
Date: Fri, 4 Jun 1993 20:44:05 GMT
Raw View
In article 23264@chaos.aoc.nrao.edu, cflatter@nrao.edu (Chris Flatters) writes:
>In article 13023@newsgate.sps.mot.com, tkacik@adtaz.sps.mot.com (Tom Tkacik) writes:
>>We have recently installed a new version of C++ based on cfront 3.0.
>>It defines __STDC__.  Is it proper for a C++ compiler to identify itself
>>as ANSI C?  It does use the ANSI C semantics, and has an ANSI preprocessor.
>
>Defining __STDC__ does not necessarily identify a compiler as an ANSI C compiler.
>ANSI C compilers are required to set __STDC__ to 1.  SunPro's port of cfront 3.0
>(and presumably other ports) sets __STDC__ to 0 so there is no conflict.

In fact it is the SunPro C++ that we have.

I left out the other half, which caused the problem.
A header file for a library we have has the following:

#ifdef __cplusplus
  /* C++ function prototypes */
#endif

#ifdef __STDC__
  /* C function prototypes */
#endif

The two set of function prototypes are not compatible, when they are both
included into a program.

Because the compiler defines both __cplusplus and __STDC__, they are both included
and an error results.

I fixed it by changing the above to:

#ifdef __cplusplus
  /* C++ function prototypes */
#else
#ifdef __STDC__
  /* C function prototypes */
#endif
#endif

Is the original version of the header file wrong, and should I complain to the
vendor?  Or is it correct to expect __cplusplus and __STDC__ to be mutually
exclusive?  (From the above answer, I assume that this code is incorrect.)

Tom Tkacik
tkacik@adtaz.sps.mot.com