This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: 'extern "C" { ...}' and 'ANSI C++ forbids ...'


Konstantin Baumann wrote:

> I am using egcs-19990714 on sparc-sun-solaris-2.6.
>
> <X11/Xlib.h> contains some declarations like:
>
>     extern XActivateScreenSaver(
>     #if NeedFunctionPrototypes
>         Display*                /* display */
>     #endif
>     );
>

Is this really the declaration? This would be broken.

Mine is
[...]
extern int XActivateScreenSaver(
[...]

>
> I include <X11/Xlib.h> inside a C++ program like this:
>
>     extern "C" {
>     #include <X11/Xlib.h>
>     };
>

This should not be required (cf. below).

>
> But I get errors like the below one when compiling this program:
>
>     /usr/openwin/include/X11/Xlib.h:2071: ANSI C++ forbids declaration
>                                           `XActivateScreenSaver' with no type
>
> I think this an error, because the <X11/Xlib.h>-header-file is included in
> "C"-mode not in "C++"-mode!
>
> Is there a switch to turn this behavior off (or a workaround)?

Standard X11 headers use a construction similar to this one:

[..]
#include <X11/Xfuncproto.h>
[..]
_XFUNCPROTOBEGIN

extern int XActivateScreenSaver(
    #if NeedFunctionPrototypes
        Display*                /* display */
    #endif
);

_XFUNCPROTOEND
[..]


_XFUNCPROTO[BEGIN|END] on a properly configured X11 installation normally take
care about extern "C" { }, therefore the extern "C" {} stuff in your code should
not be required. Check <X11/Xfuncproto.h> for the defines used for this.

I'd guess that either your X11 installation is not properly setup,  your X11
headers are broken (Openwin :-) or you simply should try to omit the extern "C"
{ .. } in your code. If you are using imake, another cause could be that gcc
support may be missing in imake's site/host configuration files or doesn't
handle c++ compiler flags correctly.

Ralf

--
Dipl.-Ing. Ralf Corsepius
Forschungsinstitut fuer Anwendungsorientierte Wissensverarbeitung (FAW)
Helmholtzstr. 16, 89081 Ulm, Germany     Tel: +49/731/501-8690
mailto:corsepiu@faw.uni-ulm.de           FAX: +49/731/501-999
http://www.faw.uni-ulm.de




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]